如何从Flex中的列表控件中删除/清除项目?

时间:2021-11-05 19:43:39

I have a list control in Flex that has been data bound to an e4x xml object from an HTTPService.

我在Flex中有一个列表控件,它已经从HTTPService绑定到e4x xml对象的数据。

I would now like to have a button that clears the list, how can I do this?

我现在想要一个清除列表的按钮,我该怎么做?

I have tried:

我试过了:


list.dataProvider = null;

which does not seem to work, I have also tried:

这似乎不起作用,我也尝试过:


list.dataProvider = {};

which clears the items but leaves [object,object] as the first item in the list...

清除项目但将[object,object]作为列表中的第一项...

2 个解决方案

#1


8  

Perhaps...

list.dataProvider = new Array();

#2


6  

Setting the dataProvider to a new Array object will throw an error:

将dataProvider设置为新的Array对象将引发错误:

Implicit coercion of a value of type Array to an unrelated type fl.data:DataProvider.

将Array类型的值隐式强制转换为不相关的类型fl.data:DataProvider。

Instead, you should use the removeAll() method provided by DataProvider:

相反,您应该使用DataProvider提供的removeAll()方法:

list.dataProvider.removeAll();

This triggers a REMOVE_ALL event in the DataProvider which, in turn, will update your list.

这会在DataProvider中触发REMOVE_ALL事件,而事件又会更新您的列表。

#1


8  

Perhaps...

list.dataProvider = new Array();

#2


6  

Setting the dataProvider to a new Array object will throw an error:

将dataProvider设置为新的Array对象将引发错误:

Implicit coercion of a value of type Array to an unrelated type fl.data:DataProvider.

将Array类型的值隐式强制转换为不相关的类型fl.data:DataProvider。

Instead, you should use the removeAll() method provided by DataProvider:

相反,您应该使用DataProvider提供的removeAll()方法:

list.dataProvider.removeAll();

This triggers a REMOVE_ALL event in the DataProvider which, in turn, will update your list.

这会在DataProvider中触发REMOVE_ALL事件,而事件又会更新您的列表。