FLEX ArrayCollection刪除過(guò)濾的數(shù)據(jù)問(wèn)題解決
更新時(shí)間:2014年06月09日 17:45:58 作者:
ArrayCollection添加過(guò)濾器后,調(diào)用removeItemAt()是無(wú)法刪除的,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下
一、問(wèn)題:
ArrayCollection添加過(guò)濾器后,部門數(shù)據(jù)不會(huì)被展現(xiàn),當(dāng)我刪除未展現(xiàn)的數(shù)據(jù)時(shí),調(diào)用removeItemAt()是無(wú)法刪除的。
二、原因:
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);
}
因?yàn)関ar oldItem:Object = localIndex[index];中l(wèi)ocalIndex是一個(gè)未被過(guò)濾的數(shù)據(jù)。
三、解決
ArrayCollection中有l(wèi)ist的屬性:
public function get list():IList
{
return _list;
}
_list就是原始數(shù)據(jù)。
所以如果要在添加了過(guò)濾器的ArrayCollection上刪除過(guò)濾的數(shù)據(jù),需要list的幫助。實(shí)現(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);
}
}
或者一個(gè)函數(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添加過(guò)濾器后,部門數(shù)據(jù)不會(huì)被展現(xiàn),當(dāng)我刪除未展現(xiàn)的數(shù)據(jù)時(shí),調(diào)用removeItemAt()是無(wú)法刪除的。
二、原因:
復(fù)制代碼 代碼如下:
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);
}
因?yàn)関ar oldItem:Object = localIndex[index];中l(wèi)ocalIndex是一個(gè)未被過(guò)濾的數(shù)據(jù)。
三、解決
ArrayCollection中有l(wèi)ist的屬性:
復(fù)制代碼 代碼如下:
public function get list():IList
{
return _list;
}
_list就是原始數(shù)據(jù)。
所以如果要在添加了過(guò)濾器的ArrayCollection上刪除過(guò)濾的數(shù)據(jù),需要list的幫助。實(shí)現(xiàn)代碼如下:
復(fù)制代碼 代碼如下:
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);
}
}
或者一個(gè)函數(shù):
復(fù)制代碼 代碼如下:
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;
}
}
}
相關(guān)文章
flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼
這篇文章主要介紹了flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07
Flex調(diào)Javascript打開(kāi)新窗口示例代碼
Flex通過(guò)調(diào)用Javascript打開(kāi)全屏的新窗口新窗口示例代碼 ,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08
flex4.0 利用外部項(xiàng)呈示器顯示List信息并添加圖片示例
利用外部項(xiàng)呈示器顯示List信息并添加圖片,在本文有個(gè)不錯(cuò)的示例,喜歡的朋友可以參考下,希望對(duì)大家有所幫助2013-09-09
Flex tree加虛線顯示效果并且替代原始圖標(biāo)
Flex tree修改默認(rèn)圖標(biāo)并且加虛線顯示效果,實(shí)在是看不下去那種巨丑無(wú)比的小箭頭+文件夾的顯示方式,具體實(shí)現(xiàn)如下,有此需求的朋友可以參考下,希望對(duì)家有所幫助2013-08-08
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表(支持多行同時(shí)拖拽,重復(fù)數(shù)據(jù)不重得添加,添加了圖表右鍵菜單)等等,感興趣的朋友可以了解下啊,或許對(duì)你有所幫助2013-01-01
flex中使用RadioButtonGroup時(shí)取出所選項(xiàng)的值的方法
flex中的RadioButtonGroup想必大家并不陌生吧,在本文將為大家介紹下在使用RadioButtonGroup時(shí)如何取出所選項(xiàng)的值,感興趣的朋友可以參考下2013-12-12

