Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 数据网格未在数组集合中显示数据_Apache Flex_Actionscript 3 - Fatal编程技术网

Apache flex 数据网格未在数组集合中显示数据

Apache flex 数据网格未在数组集合中显示数据,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我的数据网格显示的是陈旧数据,而不是它的数据提供程序(数组集合)中可用的实时数据。我已尝试重新网格化集合中的数据,但没有效果。下面是我的代码,是否有人看到可能出现的问题 <mx:Accordion/> <fx:Script> <![CDATA[ private var _gridData:ArrayCollecton = new ArrayCollection; [Bindable] public function get gridData():ArrayColle

我的数据网格显示的是陈旧数据,而不是它的数据提供程序(数组集合)中可用的实时数据。我已尝试重新网格化集合中的数据,但没有效果。下面是我的代码,是否有人看到可能出现的问题

<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>

如果我没有弄错的话,您也应该在setter上设置[Bindable],因为datagrid没有其他方法知道数据何时发生了更改


你好,Alin在我看来你想得太多了。由于您在getter/setter中没有执行任何操作,因此可以将它们去掉,只需将ArrayCollection标记为可绑定,然后将其设置为DataGrid的数据提供程序,即可:

<fx:Script>
    <![CDATA[
        [Bindable]
        public var gridData:ArrayCollecton = new ArrayCollection;

        public function loadGridData():void { 
            // Whenever you change the gridData, the DataGrid will update appropriately.
        }
    ]]>
</fx:Script>

<mx:DataGrid dataProvider="{gridData}"></mx:DataGrid>

现有代码的问题可能是您没有在setter中调度更改事件。去掉getter/setter可以让ArrayCollection为您处理该事件的调度。希望有帮助

编辑:根据更新后的问题,您可能希望尝试将渲染器更改为如下所示,如果自定义数据对象不可绑定,这将有所帮助

<?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">
<fx:Script>
    <![CDATA[
        override public function set data(value:Object):void { 
            super.data = value;
            image.source = value.url;
        }
    ]]>
</fx:Script>
    <mx:Image id="image" source="{data.url}" height="65" maintainAspectRatio="true" scaleContent="true"/>


您不需要“循环”绑定,因为在datagrid中,您不会更改集合,而是更改其项。收藏品完好无损。DataGrid的dataprovider和您的_gridData指向同一个集合

我很确定这会导致编译错误。您只需要它一次。将可绑定元标记放置在setter上被认为是多余的。然而,为此,我尝试使用“dg.invalidateProperties()”和“dg.invalidateDisplayList()”;两者都不起作用。我尝试切换到:[Bindable]public var gridData:ArrayCollection=new ArrayCollection();但这并没有解决问题。我的数据网格具有自定义项呈现器;这可能是问题的原因吗?可能。如何在自定义渲染器中设置属性?您是否覆盖了set data方法?我正在自定义渲染器中使用默认的“data”属性;请参阅上面的更新。如果您绑定到默认数据属性,并且数据对象本身不可绑定,则不会看到更改。(我假设您的数据对象在这里是某种自定义对象。)如果是这种情况,您可以将自定义数据对象类标记为可绑定,或者您可以覆盖渲染器上的set data方法,并根据覆盖的set data方法中设置的内容手动设置渲染器上的属性。为了澄清,数据对象有些自定义。但是,如果查看“loadGridData”函数,自定义对象是对象代理,然后将其添加到绑定数组集合中。因此,对象不也是绑定的吗?当提供程序更新时,您是否尝试过将数据提供程序重新绑定到DataGrid?我会去掉绑定并直接设置DP,它们似乎是不必要的,几乎可以肯定是导致问题的原因。好吧,我有(周期性的)绑定,因为我在网格中有一列,我已将其设置为可编辑。如果我删除绑定,我必须手动说明数组集合和数据网格中的更改,对吗?