欢迎来到代码驿站!

当前位置:首页 >

FLEX ArrayCollection删除过滤的数据问题解决

时间:2022-03-15 08:07:54|栏目:|点击:
一、问题:

ArrayCollection添加过滤器后,部门数据不会被展现,当我删除未展现的数据时,调用removeItemAt()是无法删除的。

二、原因:
复制代码 代码如下:

public function removeItemAt(index:int):Object
{
if (index < 0 || index >= length)
{
var message:String = resourceManager.getString(
"collections", "outOfBounds", [ index ]);
throw new RangeError(message);
}

var listIndex:int = index;
if (localIndex)
{
var oldItem:Object = localIndex[index];
listIndex = list.getItemIndex(oldItem);
}
return list.removeItemAt(listIndex);
}

因为var oldItem:Object = localIndex[index];中localIndex是一个未被过滤的数据。

三、解决

ArrayCollection中有list的属性:
复制代码 代码如下:

public function get list():IList
{
return _list;
}

_list就是原始数据。

所以如果要在添加了过滤器的ArrayCollection上删除过滤的数据,需要list的帮助。实现代码如下:
复制代码 代码如下:

public function findEmployeeInSource(id:int):OrgEmployee {
var obj:OrgEmployee = null;
var list:IList = employees.list;
var len:int = list.length;
for (var index:int = 0; index < len; index++) {
obj = list.getItemAt(index) as OrgEmployee;
if (obj.id == id) {
return obj;
}
}
return null;
}

public function deleteEmployee(id:int):void {
var obj:OrgEmployee = findEmployeeInSource(id);
if (obj != null) {
var index:int = employees.list.getItemIndex(obj);
employees.list.removeItemAt(index);
}
}

或者一个函数:
复制代码 代码如下:

public function deleteEmployee(id:int):void {
var obj:OrgEmployee = null;
var list:IList = employees.list;
var len:int = list.length;
for (var index:int = 0; index < len; index++) {
obj = list.getItemAt(index) as OrgEmployee;
if (obj.id == id) {
list.removeItemAt(index);
return;
}
}
}

上一篇:React Hook的使用示例

栏    目:

下一篇:docker 容器上编译 go 程序提示找不到文件问题

本文标题:FLEX ArrayCollection删除过滤的数据问题解决

本文地址:http://www.codeinn.net/misctech/196290.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有