Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List Flex在mx:列表中选择或取消选择项目时,如何更改dataProvider中的项目_List_Apache Flex - Fatal编程技术网

List Flex在mx:列表中选择或取消选择项目时,如何更改dataProvider中的项目

List Flex在mx:列表中选择或取消选择项目时,如何更改dataProvider中的项目,list,apache-flex,List,Apache Flex,Flex在mx:列表中选择或取消选择项(多选)时,如何更改dataProvider中的项 我只想让我的数据动态地反映我在列表中选择的项目。在此基础上,对列表进行一些排序,例如,当选定项目时,将其放在列表的第一位,当取消选定项目时,将其放回原始位置……您可以使用来获取/添加/删除列表中的项目 下面是如何创建光标的代码示例,基于此,您只需应用所需的逻辑即可 var col:ICollectionView = ICollectionView(list.dataProvider); var myCur

Flex在mx:列表中选择或取消选择项(多选)时,如何更改dataProvider中的项

我只想让我的数据动态地反映我在列表中选择的项目。在此基础上,对列表进行一些排序,例如,当选定项目时,将其放在列表的第一位,当取消选定项目时,将其放回原始位置……

您可以使用来获取/添加/删除列表中的项目

下面是如何创建光标的代码示例,基于此,您只需应用所需的逻辑即可

var col:ICollectionView =  ICollectionView(list.dataProvider);
var myCursor:IViewCursor = col.createCursor(); 
//do the logic using the myCursor functions
...
//refresh the collection to the changes reflect in the list
col.refresh();

您可以查看有关它的更多信息。

您可以将事件侦听器添加到列表中,以便每当发生选择/取消选择时,它都会触发。

<s:List id="myList"
    labelField="firstName" 
    change="selectionChangedHandler(event)"
    dataProvider="{peopleArray}">
</s:List>

....
protected function selectionChangedHandler(event:IndexChangeEvent):void
{
    var currentIndx:int = event.currentTarget.selectedIndex;
    var currentDataItem:Object = event.currentTarget.selectedItem;
    peopleArray.removeItemAt(currentIndx);
    peopleArray.addItemAt(currentDataItem,0);
    peopleArray.refresh();
}

....
受保护的函数selectionChangedHandler(事件:IndexChangeEvent):无效
{
var currentIndx:int=event.currentTarget.selectedIndex;
var currentDataItem:Object=event.currentTarget.selectedItem;
peopleArray.removietemat(currentIndx);
peopleArray.addItemAt(currentDataItem,0);
peopleArray.refresh();
}
我还没有运行它,但您可能还需要在刷新列表上设置选择