Apache flex 列表中的数据绑定

Apache flex 列表中的数据绑定,apache-flex,flash-builder,Apache Flex,Flash Builder,我试图将ArrayList中的数据绑定到一个列表,但这里只有最后一个元素显示在列表上(99),而不是ArrayList的全部内容 private function completeHandler(event:Event):void { var xmlData:XML = XML(event.target.data); trace(xmlData); var i:int = 0; fo

我试图将ArrayList中的数据绑定到一个列表,但这里只有最后一个元素显示在列表上(99),而不是ArrayList的全部内容

private function completeHandler(event:Event):void
        {
            var xmlData:XML = XML(event.target.data);
            trace(xmlData);
             var i:int = 0;
            for (i;i<100;i++)
            {
                var arr:ArrayList = new ArrayList();
                arr.addItem(i);
                trace(arr);
            } 
            list.dataProvider = arr;
        }
私有函数completeHandler(事件:event):void
{
var xmlData:XML=XML(event.target.data);
跟踪(xmlData);
变量i:int=0;

对于(i;i,您正在创建一个ArrayList,其中包含一项100次。替换为此,您应该可以:

var arr:ArrayList = new ArrayList();
for (var i:int = 0; i<100; i++) {
    arr.addItem(i);
} 

(请注意,这不是数据绑定:它只是设置
dataProvider
属性)

检查此代码这将帮助您

您可以根据列表的行数浏览所有数据

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  minWidth="955" minHeight="600">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]private var _index:int = 0;
            private var _coll:ArrayCollection = new ArrayCollection([{name:'ashish',age:'28'},{name:'abhi',age:'29'},{name:'kunal',age:'27'},
                {name:'ashish1',age:'28'},{name:'abhi1',age:'29'},{name:'kunal1',age:'27'},
                {name:'ashish2',age:'28'},{name:'abhi2',age:'29'},{name:'kunal2',age:'27'},
                {name:'ashish3',age:'28'},{name:'abhi3',age:'29'},{name:'kunal3',age:'27'}]);

            protected function button1_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                if((_index-li.rowCount>=0))
                    _index =  _index - li.rowCount;
            }


            protected function button2_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                if((_index+li.rowCount<_coll.length))
                    _index =  _index + li.rowCount;
            }

        ]]>
    </mx:Script>

    <mx:List id="li" dataProvider="{_coll.source.slice(_index,(_index+li.rowCount))}" labelField="name" rowCount="3" width="100"/> 

    <mx:HBox>
        <mx:Button label="&lt;-" click="button1_clickHandler(event)"/>
        <mx:Button label="->" click="button2_clickHandler(event)"/>
    </mx:HBox>
</mx:Application>

=0))
_index=\u index-li.rowCount;
}
受保护的功能按钮2\u clickHandler(事件:MouseeEvent):无效
{
//TODO自动生成的方法存根
如果(_index+li.rowCount
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  minWidth="955" minHeight="600">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]private var _index:int = 0;
            private var _coll:ArrayCollection = new ArrayCollection([{name:'ashish',age:'28'},{name:'abhi',age:'29'},{name:'kunal',age:'27'},
                {name:'ashish1',age:'28'},{name:'abhi1',age:'29'},{name:'kunal1',age:'27'},
                {name:'ashish2',age:'28'},{name:'abhi2',age:'29'},{name:'kunal2',age:'27'},
                {name:'ashish3',age:'28'},{name:'abhi3',age:'29'},{name:'kunal3',age:'27'}]);

            protected function button1_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                if((_index-li.rowCount>=0))
                    _index =  _index - li.rowCount;
            }


            protected function button2_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                if((_index+li.rowCount<_coll.length))
                    _index =  _index + li.rowCount;
            }

        ]]>
    </mx:Script>

    <mx:List id="li" dataProvider="{_coll.source.slice(_index,(_index+li.rowCount))}" labelField="name" rowCount="3" width="100"/> 

    <mx:HBox>
        <mx:Button label="&lt;-" click="button1_clickHandler(event)"/>
        <mx:Button label="->" click="button2_clickHandler(event)"/>
    </mx:HBox>
</mx:Application>