2014-03-13 54 views
0

我有,我已經定義2個自定義狀態這個自定義列表項呈示:Flex移動防止項目渲染狀態由回收

<s:states> 
    <s:State name="expand"/> 
    <s:State name="collapse"/> 
</s:states> 

當我選擇列表項目之一,它將改變國家崩潰。現在,無論何時我選擇列表中的第一個或最後一個項目並刷新數據提供者,兩個項目的當前狀態都將交換位置。

請指導我如何保留的itemRenderer的狀態。謝謝。

注:這一切運作良好時,我改變usevirtuallayout爲false。但是,這不是我想改變的。

[編輯] 以下是我項呈示代碼:

<fx:Script> 
    <![CDATA[ 

protected function init(event):void 
{ 
    currentState = "collapse"; 
} 

override public function set data(value:Object):void 
{ 
    trace(currentState.toString()); 
} 

protected function btn_clickHandler(event:MouseEvent):void 
{ 
    currentState = "expand"; 
} 

]]> 
</fx:Script> 

<s:states> 
    <s:State name="expand"/> 
    <s:State name="collapse"/> 
</s:states> 

<s:Button id="changeStateButton" click="btn_clickHandler(event)"/> 

上面的例子是一個簡單的項目渲染器,其中一個單一的按鈕將改變的itemRenderer的將currentState。我在數據提供者中有3個項目,默認情況下它們中的每一個都處於「崩潰」狀態。這是從一組數據功能的跟蹤結果:

collapse 
collapse 
collapse 

當我點擊最後一個項目的按鈕......這將是跟蹤結果:

collapse 
collapse 
expand 

現在,當我刷新數據提供者通過調用該函數「arraycollection.refresh()」...這是結果:

expand 
collapse 
collapse 

有人可以解釋這種情況嗎?請注意,當useVirtualLayout設置爲true這只是發生......

+0

請給更多的上下文。用於通過示例顯示列表的代碼。 –

+0

喜@PascalLeMerrer請參見新編輯我上面添加 –

回答

0

嘗試更新數據提供商後重新分配的項目渲染器。

//update data provider 
itemList.dataProvider = myCollection; 
//update the item renderer 
itemList.itemRenderer = new ClassFactory(cutomItemRenderer); 

這個解決方案當然會更耗費資源。