我在我的flex项目中有一个组件A,人们可以投票给他们最喜欢的艺术家。有人“喜欢”一位艺术家,它会在我的数据库中更新。还有一个组件B显示了最受欢迎的艺术家的图表。我在Flex中调用creationcomplete数据库中的数据。问题是,当一个人首先对艺术家投票时,它将不会在数据网格中可见,直到用户重新加载主页面(?)或重新打开整个应用程序。所以我想知道如何每次有人添加投票到我的数据库我可以更新datagrid。我现在正在使用更新按钮,但这当然不是很友好。欢迎任何帮助!Flex:更新datagrid每次添加一个值(来自另一个组件)
0
A
回答
1
使用一个ArrayCollection,你只要把它绑定所有的方式通过所有部件
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
public var artistData:ArrayCollection = new ArrayCollection([
{artistName : "Paula", artistLikes : "0"},
{artistName : "Bob", artistLikes : "0"},
{artistName : "Arthur", artistLikes : "0"}
]);
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:DataGrid id="artists" dataProvider="{artistData}" width="100%" height="150">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="artistName" headerText="Artist Name"/>
<s:GridColumn dataField="artistLikes" headerText="Artist Likes"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<components:CompA artistDataInCompA="{artistData}" height="100"/>
<components:CompB artistDataInCompB="{artistData}" height="100"/>
假设你在com中增加喜欢P A(不要忘记调用刷新()上的ArrayCollection)
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var artistDataInCompA:ArrayCollection;
protected function button_clickHandler(name:String):void
{
var index:Number = getItemIndexByProperty(artistDataInCompA, "artistName", name);
var numLikes:Number = artistDataInCompA[index].artistLikes;
// Here you update your PHP
// HTTPService...
// and the ArrayCollection that is binded all the way through all components
artistDataInCompA[index].artistLikes = numLikes + 1;
artistDataInCompA.refresh();
}
protected function getItemIndexByProperty(array:ArrayCollection, property:String, value:String):Number
{
for (var i:Number = 0; i < array.length; i++)
{
var obj:Object = Object(array[i])
if (obj[property] == value)
return i;
}
return -1;
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Button label="Add a like to Paula" click="button_clickHandler('Paula')"/>
<s:Button label="Add a like to Bob" click="button_clickHandler('Bob')"/>
<s:Button label="Add a like to Arthur" click="button_clickHandler('Arthur')"/>
现在,你有你的份B做什么
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var artistDataInCompB:ArrayCollection;
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Label text="Paula has {artistDataInCompB.getItemAt(0).artistLikes} like(s)"/>
<s:Label text="Bob has {artistDataInCompB.getItemAt(1).artistLikes} like(s)"/>
<s:Label text="Arthur has {artistDataInCompB.getItemAt(2).artistLikes} like(s)"/>
0
如果您想要缓慢响应,您应该使用服务器端脚本系统(如PHP)为您的操作脚本代码添加通信功能。如果您想要实时响应,则应使用套接字服务或Web服务。
1
每次投票时,在发送命令添加一个投票后,将这些行添加到函数中。
public function voteUpFunction():void
{
// Your Code to Vote up <Enter Code here>
YourDataGridId.dataprovider = null;
//call new listofLikedPersons using conn.call <Enter Code here>
YourDataGridId.dataprovider = listOfLikedPersons;
}
希望这会有所帮助,告诉我,如果它解决了问题
0
它是一个简单的,你只需要维护一个计时器变量,并在某个时间让1秒钟,你只需要刷新datagrid的dataprovider。
祝您有愉快的一天。
相关问题
- 1. 为什么ngFor不会更新时,添加数组来自另一个组件?
- 2. 批次:添加%的一个值来声明另一个变量
- 3. Flex DataGrid:根据另一个值更改值?
- 4. 对于每一行,创建一个新行以添加来自另一个文件的多个条目
- 5. 更新与来自另一个表
- 6. 来自另一个select的SQL更新
- 7. 更新一个DataGrid
- 8. flex 4 - 在另一个顶层上叠加一个组件?
- 9. 从另一个组件更新一个React的组件状态
- 10. 添加一个新行的DataGrid(WPF)
- 11. 点击更新另一个组件
- 12. 成员一组来自另一个域
- 13. 来自另一个表的SSIS更新表值
- 14. 将一个数组中的值添加到另一个
- 15. 如何插入一个单词添加来自另一个添加
- 16. Flex/DataGrid:更新dataProvider的每一行更改
- 17. 每次添加一个。初学者
- 18. Excel/VBA更新单元格每次在另一个单元格中更改值
- 19. 更新值从一个表到另一
- 20. SL4 | DomainDataSource/DataGrid |添加一个空行来插入新项目
- 21. Vue.js来自另一组件
- 22. 比较一个值与数组的每个值,它是另一个数组内
- 23. Flex - 如何在另一个组件中定义一个功能?
- 24. 每10秒更新一次自我更新部件Handler.postDelayed问题
- 25. 更新值发送到另一个组件角2
- 26. 为json数组中的每个值添加一个键javascript
- 27. 如何给每个数组项添加一个值?
- 28. 添加另一个div来脚本
- 29. 每次刷新都会将另一个监听器添加到socket.io连接
- 30. 数组包含来自另一个数组的任何值?
Wondefull!谢谢:) – 2011-12-19 13:33:32
+1解决问题的办法....但你必须允许askers工作他们自我和理解。我认为只是提供逻辑就足够了:) – 2011-12-21 05:46:06