FLEX ArrayCollection删除过滤的数据问题解决
ArrayCollection添加过滤器后,部门数据不会被展现,当我删除未展现的数据时,调用removeItemAt()是无法删除的。
二、原因:
publicfunctionremoveItemAt(index:int):Object
{
if(index<0||index>=length)
{
varmessage:String=resourceManager.getString(
"collections","outOfBounds",[index]);
thrownewRangeError(message);
}
varlistIndex:int=index;
if(localIndex)
{
varoldItem:Object=localIndex[index];
listIndex=list.getItemIndex(oldItem);
}
returnlist.removeItemAt(listIndex);
}
因为varoldItem:Object=localIndex[index];中localIndex是一个未被过滤的数据。
三、解决
ArrayCollection中有list的属性:
publicfunctiongetlist():IList
{
return_list;
}
_list就是原始数据。
所以如果要在添加了过滤器的ArrayCollection上删除过滤的数据,需要list的帮助。实现代码如下:
publicfunctionfindEmployeeInSource(id:int):OrgEmployee{
varobj:OrgEmployee=null;
varlist:IList=employees.list;
varlen:int=list.length;
for(varindex:int=0;index<len;index++){
obj=list.getItemAt(index)asOrgEmployee;
if(obj.id==id){
returnobj;
}
}
returnnull;
}
publicfunctiondeleteEmployee(id:int):void{
varobj:OrgEmployee=findEmployeeInSource(id);
if(obj!=null){
varindex:int=employees.list.getItemIndex(obj);
employees.list.removeItemAt(index);
}
}
或者一个函数:
publicfunctiondeleteEmployee(id:int):void{
varobj:OrgEmployee=null;
varlist:IList=employees.list;
varlen:int=list.length;
for(varindex:int=0;index<len;index++){
obj=list.getItemAt(index)asOrgEmployee;
if(obj.id==id){
list.removeItemAt(index);
return;
}
}
}
热门推荐
10 六一婚礼文案祝福语简短
11 新年祝福语和语句简短
12 虎年开新车祝福语简短
13 送外卖祝福语大全简短
14 佛教生日祝福语简短大全
15 美丽晚霞祝福语简短句
16 师生聚餐的祝福语简短
17 国庆求婚祝福语简短精辟
18 祖国生日祝福语简短英文