FLEX ArrayCollection刪除過濾的數(shù)據(jù)問題解決
更新時間:2014年06月09日 17:45:58 作者:
ArrayCollection添加過濾器后,調用removeItemAt()是無法刪除的,下面有個不錯的解決方法,大家可以參考下
一、問題:
ArrayCollection添加過濾器后,部門數(shù)據(jù)不會被展現(xiàn),當我刪除未展現(xiàn)的數(shù)據(jù)時,調用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];中l(wèi)ocalIndex是一個未被過濾的數(shù)據(jù)。
三、解決
ArrayCollection中有l(wèi)ist的屬性:
public function get list():IList
{
return _list;
}
_list就是原始數(shù)據(jù)。
所以如果要在添加了過濾器的ArrayCollection上刪除過濾的數(shù)據(jù),需要list的幫助。實現(xiàn)代碼如下:
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);
}
}
或者一個函數(shù):
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添加過濾器后,部門數(shù)據(jù)不會被展現(xiàn),當我刪除未展現(xiàn)的數(shù)據(jù)時,調用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];中l(wèi)ocalIndex是一個未被過濾的數(shù)據(jù)。
三、解決
ArrayCollection中有l(wèi)ist的屬性:
復制代碼 代碼如下:
public function get list():IList
{
return _list;
}
_list就是原始數(shù)據(jù)。
所以如果要在添加了過濾器的ArrayCollection上刪除過濾的數(shù)據(jù),需要list的幫助。實現(xiàn)代碼如下:
復制代碼 代碼如下:
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);
}
}
或者一個函數(shù):
復制代碼 代碼如下:
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動態(tài)顯示圖表實現(xiàn)代碼
Flex3 DataGrid拖拽到ClumnChart動態(tài)顯示圖表(支持多行同時拖拽,重復數(shù)據(jù)不重得添加,添加了圖表右鍵菜單)等等,感興趣的朋友可以了解下啊,或許對你有所幫助2013-01-01
flex中使用RadioButtonGroup時取出所選項的值的方法
flex中的RadioButtonGroup想必大家并不陌生吧,在本文將為大家介紹下在使用RadioButtonGroup時如何取出所選項的值,感興趣的朋友可以參考下2013-12-12

