开发者

Starting with an empty dataProvider for a <List>

开发者 https://www.devze.com 2023-01-01 02:51 出处:网络
I\'m using a List which I need to be empty at the start. I\'m adding items to it as needed by clicking a button. Since it\'s empty, I haven\'t added a dataProvider property

I'm using a List which I need to be empty at the start. I'm adding items to it as needed by clicking a button. Since it's empty, I haven't added a dataProvider property

<s:List id="thelist" itemRenderer="listIR" />
开发者_开发知识库

To add an item, I'm adding it to the dataProvider directly

thelist.dataProvider.addItem()

but when I do that, it gives me this error

 #1009: Cannot access a property or method of a null object reference.

Also I have a debugging Alert in the listIR itemRenderer itself and I see that when the list is created, I get that alert twice as if 2 itemRenderers were created, even though the list is supposed to be empty at the start.

Any ideas what's wrong with this itemRenderer? How do I start with an empty dataProvider and add items smoothly to it?


The dataProvider of the List ist null. You have to set an empty implementation of the IList or ICollectionView interface, e.g.:

<s:List id="thelist" itemRenderer="listIR" dataProvider="new ArrayCollection()"/>


Because there was not thelist.dataProvider set then this value is initially null. so null.addItem() is not possible.

You should have see at debug time an instantiated Array or ArrayCollection as dataProvider before calling the addItem();

fix 1: described by << Daniel Engmann >>

fix 2:

if(!thelist.dataProvider) thelist.dataProvider = new ArrayCollection();
thelist.dataProvider.addItem();
0

精彩评论

暂无评论...
验证码 换一张
取 消