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調(diào)用webservice中的自定義類的方法
flex如何調(diào)用webservice中的自定義類,下面有個(gè)不錯(cuò)的示例,不了解的朋友可以參考下2014-01-01flex4獲取當(dāng)前窗口的長(zhǎng)度與寬度的方法
讓新窗口看上去像新的一頁(yè),于是就投機(jī)想讓PopUp的窗口界面大小自適應(yīng)屏幕,下面是flex4 獲取當(dāng)前窗口的長(zhǎng)度與寬度示例,需要的朋友可以參考下2014-07-07Flex DataGrid自動(dòng)編號(hào)示例
這篇文章主要介紹了Flex DataGrid如何自動(dòng)編號(hào),感興趣的朋友可以參考下2014-05-05flex打印操作(FlexPrintJob)還有分頁(yè)打印操作具體實(shí)現(xiàn)
如果要使用分頁(yè)效果,則必須使用標(biāo)簽"PrintAdvancedDataGrid"(Flex3中的標(biāo)簽)才能夠?qū)崿F(xiàn)分頁(yè)效果,感興趣的朋友可以參考下2013-04-04Flex 基于數(shù)據(jù)源的Menu Tree實(shí)現(xiàn)代碼
由外部參數(shù)flashvars指定數(shù)據(jù)源的文件位置或render鏈接,在源數(shù)據(jù)上加href和target屬性來(lái)控制打開(kāi)窗口,可自定義父節(jié)點(diǎn)和子節(jié)點(diǎn)圖標(biāo),不設(shè)置采用系統(tǒng)默認(rèn),感興趣的你可以了解下啊,或許對(duì)你有所幫助2013-01-01Flex字體加粗問(wèn)題只能對(duì)英文的字體加粗
在flex中對(duì)label進(jìn)行字體加粗的時(shí)候,只能對(duì)英文的字體加粗,而中文的就不可以加粗,解決方法如下,希望對(duì)大家有所幫助2014-01-01flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼
這篇文章主要介紹了flex 遍歷Object對(duì)象內(nèi)容的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07