2013-03-15 72 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();