Flex如何在mx:List
中选择或取消选择项目(多项选择)时更改dataProvider中的项目我只想让我的数据动态反映我在列表中选择的项目。在此基础上对列表进行一些排序,例如在选择项目时首先在列表中选择项目,并在取消选择项目时返回原始位置....
答案 0 :(得分:0)
您可以使用列表中的IViewCursor至get/add/remove
项。
以下是如何创建游标的代码示例,基于您只需要应用所需的逻辑。
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();
Here您可以查看更多相关信息。
答案 1 :(得分:0)
您可以向列表中添加一个事件侦听器,以便每当选择/取消选择时触发它。
<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();
}
我还没有运行它,但您可能还需要在刷新列表上设置选择。