FLEX ArrayCollection删除过滤的数据问题解决
更新时间:2014年06月09日 17:45:58 作者:
ArrayCollection添加过滤器后,调用removeItemAt()是无法删除的,下面有个不错的解决方法,大家可以参考下
一、问题:
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;
}
}
}
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;
}
}
}
相关文章
flex4.0 利用外部项呈示器显示List信息并添加图片示例
利用外部项呈示器显示List信息并添加图片,在本文有个不错的示例,喜欢的朋友可以参考下,希望对大家有所帮助2013-09-09
Flex3 DataGrid拖拽到ClumnChart动态显示图表实现代码
Flex3 DataGrid拖拽到ClumnChart动态显示图表(支持多行同时拖拽,重复数据不重得添加,添加了图表右键菜单)等等,感兴趣的朋友可以了解下啊,或许对你有所帮助2013-01-01
flex中使用RadioButtonGroup时取出所选项的值的方法
flex中的RadioButtonGroup想必大家并不陌生吧,在本文将为大家介绍下在使用RadioButtonGroup时如何取出所选项的值,感兴趣的朋友可以参考下2013-12-12


最新评论