2014-09-30 16 views
0

如何在Flex 3上的列表控件上動態設置selectedIndices?如何在flex 3上的列表控件上動態設置selectedIndices?

我在重複控制中使用列表。我有一個選項多選列表。當我選擇多個選項時,我可以將選定的索引作爲數組存儲並存儲在數據庫中。同時列出所選索引屬性的列表控件中的選定值時,它將不會正確設置。在這裏我給了我的代碼。

<mx:VBox y="30" x="1" id="vboxState"> 
     <mx:Repeater id="rptrRadioState" dataProvider="{rptrArr}"> 
      <mx:HBox> 
       <mx:List id="cmbstateradio" selectedIndices="{new Array(1,3)}" dataProvider="{listarr}" allowMultipleSelection="true" change="(event.currentTarget.getRepeaterItem().selectedval = cmbstateradio[event.target.repeaterIndices].selectedIndices)"/> 
      </mx:HBox> 
     </mx:Repeater> 
    </mx:VBox> 

它工作正常。但是,如果我會用下面提到的方式嘗試,那不是工作。

[Bindable] 
      public var arr:Array = new Array(1,3); 

      [Bindable] 
      public var rptrArr:ArrayCollection = new ArrayCollection([{label:"TestA",data:0,selectedval:new Array(1,3)},{label:"TestB",data:1,selectedval:arr},{label:"TestC",data:2,selectedval:arr}]); 

    <mx:VBox y="30" x="1" id="vboxState"> 
     <mx:Repeater id="rptrRadioState" dataProvider="{rptrArr}"> 
      <mx:HBox> 
       <mx:List id="cmbstateradio" selectedIndices="{new Array(rptrRadioState.currentItem.selectedval)}" dataProvider="{listarr}" allowMultipleSelection="true" change="(event.currentTarget.getRepeaterItem().selectedval = cmbstateradio[event.target.repeaterIndices].selectedIndices)"/> 
      </mx:HBox> 
     </mx:Repeater> 
    </mx:VBox>   

回答

0

問題可能出在這部分代碼:

"{new Array(rptrRadioState.currentItem.selectedval)}" 

當我看到你創建數組的數組。嘗試從語句中刪除新的Array()。然後它會看下一個:

"{rptrRadioState.currentItem.selectedval}" 

另外,您需要使用不同的陣列selectedIndices。例如:

[Bindable] 
public var rptrArr:ArrayCollection = new ArrayCollection([ 
                   {label: "TestA", data: 0, selectedval: [1, 3]}, 
                   {label: "TestB", data: 1, selectedval: [1, 3]}, 
                   {label: "TestC", data: 2, selectedval: [1, 3]} 
                 ]); 

P.S.不幸的是,我無法解釋爲什麼它不適用於所有列表'selectedIndices的一個數組實例。也許別人知道這個答案。

+0

我試了。它也沒有work.i不能得到解決方案... – venkat 2014-10-06 05:52:16

+0

我更新了我的答案。 – Crabar 2014-10-06 07:08:30

+0

謝謝crabar.But它也沒有工作。這樣只會選擇第一個索引。這是零指數。 – venkat 2014-10-06 10:21:10

0

您在不同的元素中使用相同的數組arr。如果你真的需要這種行爲,最好試着克隆數組arr,而不是將它分配給許多組件。嘗試不使用相同的陣列ARR我認爲這是問題。 flex 3上的某些元素不能在不同的可視組件中共享。我更喜歡在重複事件中爲重複的組件分配屬性,而不是在線進行。

相關問題