【发布时间】:2010-10-07 16:06:08
【问题描述】:
我的数据网格显示的是陈旧数据,而不是其数据提供程序(数组集合)中可用的实时数据。我尝试刷新集合中的数据,但这没有效果。下面是我的代码,有没有人看到可能是什么问题?
<mx:Accordion/>
<fx:Script>
<![CDATA[
private var _gridData:ArrayCollecton = new ArrayCollection;
[Bindable] public function get gridData():ArrayCollection { return _gridData; }
public function set gridData(value:ArrayCollection):void { _gridData = value; }
public function loadGridData():void {
// imgCollection is the data returned from the server
var tempCollection:ArrayCollection = new ArrayCollection();
for (var i:int = 0; i < imgCollection.length; i++)
{
var img:Object = new Object();
img.id = imgCollection.getItemAt(i).imgId;
img.url = "http://..." + imgCollection.getItemAt(i).imgId;
img.caption = (imgCollection.getItemAt(i).imgCaption == null) ? "": imgCollection.getItemAt(i).imgCaption;
img.group = images;
tempCollection.addItem(new ObjectProxy(img));
}
gridData = tempCollection;
<!-- Use http service to get data and save it in grid data array collection, this is run on accordion create completion and whenever data is added or removed from the array collection -->
}
]]>
</fx:Script>
<!-- NOTE: There is a cyclic binding between the data grid and the gridData array collection -->
<fx:Binding source="dg.dataProvider as ArrayCollection" destination="gridData"/>
...
...
<s:NavigatorContent>
<s:Panel>
<mx:DataGrid dataProvider="{gridData}" ...>
...
...
</mx:DataGrid>
</s:Panel>
</s:NavigatorContent>
更新: 我尝试了下面提到的建议,但是,它们并没有解决问题。数据网格有自定义项渲染器,这可能是问题吗?
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<mx:Image id="image" source="{data.url}" height="65" maintainAspectRatio="true" scaleContent="true"/>
</s:MXDataGridItemRenderer>
【问题讨论】:
-
您是否尝试在提供程序更新时将 dataProvider 重新绑定到 DataGrid?
-
我会摆脱绑定并直接设置 DP,它们似乎是不必要的,而且几乎肯定会导致问题。
-
好吧,我有(循环)绑定,因为我在网格中有一个可编辑的列。如果我删除绑定,我将不得不手动考虑数组集合和数据网格中的更改,对吗?
标签: apache-flex actionscript-3