2013-03-15 68 views
1

是否可以仅刷新Flex DataProvider中的一个项目?只刷新数据提供者的一部分。可能?

例如,实现这样的事情

[Bindable] 
private var nodes : VectorCollection = new VectorCollection(); 

/* thousands of insertions on nodes */ 

/* Triggered by some event */ 
public function nodeStatusChanged(nodeId : Number) : void { 
     nodes.refresh(nodeId); 
} 

,而不是在每一个nodeStatusChanged(nodeId)呼叫

任何想法做 nodes.refresh()? 在此先感谢。

+0

我不知道我理解你的问题。如果您更改集合中的一个元素,它应该**派发相应的CollectionChange事件。我在这里做一些假设:1)你使用的VectorCollection类实现IList接口(因此你可以使用基于矢量的集合来处理任何需要ArrayCollection或类似IList类的东西),2)VectorCollection调度合适的CollectionChange事件表示集合中的一个或多个项目已更改(如ArrayCollection所做的那样)。 – 2013-03-16 00:25:25

+0

PS:几年前,我写了[我自己的VectorCollection类](https://github.com/sunild/Flex-Collection-Utils),并发送了正确的CollectionChange事件。实施的目标是通过减少将要发生的铸造量来尽可能保持高性能。 – 2013-03-16 00:28:32

回答

1

我不确定我完全理解你的问题是什么,但是如果你希望只有一个事件由你的集合在同时插入大量值时发送,那么你应该使用中间向量:

var tempVector:Vector.<Node> = new Vector.<Node>(); 
// Do whatever you need to perform here; 
nodes.vector = tempVector; 
nodes.refresh(); 

你在哪里用你的矢量用的类名替换Node。 在你refresh()方法,你再派遣您的活动:

dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)); 
+0

请注意,您确实应该派发适当的集合更改事件...例如,您没有指定更改类型(CollectionEventKind)。您还没有指定已更改的项目。例如,当事件的“种类”为CollectionEventKind.ADD时,它们指定添加的项目的索引以及添加的项目。当它是替换时,传递索引,旧项目和新项目。这不像你的例子那么简单:) – 2013-03-16 05:13:52

1

你可以用这个

尝试更新一个项目在vectorcollection您可以在ICollectionView使用itemUpdated()

如果对象未实现IEventDispatcher接口,也可以使用itemUpdated()方法通知集合对数据提供者对象的更改;

[Bindable] 
private var nodes:VectorCollection = new VectorCollection(); 

当您更新的节点VectorCollection一个字段,如下,控制不会自动更新,因此使用itemUpdated()。

nodes.getItemAt(0).field1="someOtherValue"; 

nodes.itemUpdated(nodes.getItemAt(0)); 

Instead of nodes.refresh();