开发者

Flex ArrayCollection getItemIndex always -1

I have a question, why doesn't this work?

I have an ArrayCollection with data; a trace of random index of this using

ObjUtil.toString(arrc.getItemAt(index))

gives me

(Object)#0  
  label = "VALUE"  
  value = 20  

I then create an object:

var newObj:Object = new Object()  
newObj.label = "VALUE"  
newObj.value = 20  

A trace of this gives:

(Object)#0  
  label = "VALUE"  
  value = 20  

Now I do:

arrc.getItemIndex(newObj)  

and it always gives me -1.

开发者_如何学编程

Does anyone know where I'm going wrong?


Just a bit of clarification.. You're not actually adding that object to the collection? You're creating an object that is the same as an object in the collection and using it to get the index?

The newObj is not the same as the object in the arraycollection.. they just have the same values. The getItemIndex method will only 'find' an object if it's actually the same object (it's not going to drill down and compare member variables).


getItemIndex is searching for the same item (instance) and not for an equal item with equal property values.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜