过滤 arraycollection 后 ArrayCollection 索引发生变化
我有一个高级数据网格并使用 arraycollection 填充一些数据。我正在过滤 arraycollection,arraycollection 索引已更改。
Arraycollection:- [0] - name: abc
[1] - name: hello
[2] - name: hello1
[3] - name:hai
将 arraycollection 过滤为 'hell' 后,数组集合显示如下:
Arraycollection:-
[0] - name: hello1
[1] - name: hello
我可以知道过滤后索引发生变化的原因吗?
* 没有用于过滤的服务器端代码。它只是柔性侧过滤。
I have a advanced datagrid and populating some data by using arraycollection. And i am filtering the arraycollection, the arraycollection index got changed.
Arraycollection:- [0] - name: abc
[1] - name: hello
[2] - name: hello1
[3] - name:hai
after filtering the arraycollection as 'hell' , the array collection is displaying like the below:
Arraycollection:-
[0] - name: hello1
[1] - name: hello
Can i know the reason why the index got changed after filter it?
* no server side code for filtering. it is only flex side filtering.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ArrayCollection
不是关联数组或映射,它是由整数索引的普通数组的包装器。即,您不能拥有仅包含索引 1 和 2 处的元素的数组。
来自 过滤器文档:
The
ArrayCollection
not an associative array or a map, it's a wrapper for an ordinary array indexed by integers.I.e., you can't have an array which only contains an element at index 1 and 2.
From the documentation of filter:
ArrayCollection 有一些非常好的和独特的属性。
其中一个属性是可以绑定。
此绑定属性允许您将集合设置为 Flex 对象(如 TileList)的数据提供者。
因此,当集合被过滤时,TileList 将使用过滤后的数据自动重新填充,无需额外代码。
另一个属性是 source 。这是未过滤/未更改的数据。
当将过滤器应用于集合时,新数据将是源减去未通过过滤测试的元素。
正如您所看到的,您的过滤器仅传递了 2 个项目并返回了 2 个元素的新集合。
您不能假设任何给定元素的索引值不会改变
还可以使用 arrCol.refresh( );在应用数据绑定过滤器后。
ArrayCollection has a few very nice and unique properties.
One property is that it can be bound.
This binding property allows you to set the collection as a dataprovider for a flex object like a TileList.
So when the collection is filtered the TileList will repopulate automatically using the filtered data with no additional code.
Another property is source. This is the unfiltered/unchanged data.
When a filter has been applied to the collection the new data will be the source minus the elements that failed the filter test.
As you can see your filter only passed 2 items and returned the new collection of 2 elements.
You can NOT assume the index values of any given element will not change
Also use arrCol.refresh( ); after you apply a filter for databinding to work.