简体   繁体   English

如何在Flex 3的列表控件上动态设置selectedIndices?

[英]How to set selectedIndices dynamically on list control on flex 3?

How to set selectedIndices dynamically on list control on flex 3? 如何在Flex 3的列表控件上动态设置selectedIndices?

I am using list within repeater control. 我在转发器控件中使用列表。 I have an option multiple selection for list . 我可以选择list的多个选项。 when i am selecting the multiple options i can get selected indices as array and stored in database. 当我选择多个选项时,我可以获得选定的索引作为数组并存储在数据库中。 At the same time while list out those selected values in an list control on selected indices property it will not set correctly. 同时,在选定索引属性的列表控件中列出那些选定值时,将无法正确设置。 Here i have given my code. 在这里,我给出了我的代码。

    <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>

It is works fine. 很好。 But if i would try in below mentioned way it was not work. 但是,如果我尝试使用下面提到的方式,那是行不通的。

    [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>        

Problem may be in this part of code: 问题可能出在这部分代码中:

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

As I see you create array of array. 如我所见,您创建了array数组。 Try to remove new Array() from statement. 尝试从语句中删除新的Array()。 Then it will be look next: 然后将是下一步:

"{rptrRadioState.currentItem.selectedval}"

Also, you need to use different arrays for selectedIndices . 另外,您需要对selectedIndices使用不同的数组。 For example: 例如:

[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]}
                                                         ]);

PS Unfortunately, I cannot explain why it doesn't work with one instance of array for all lists' selectedIndices . PS不幸的是,我无法解释为什么它不适用于所有列表的selectedIndices一个数组实例。 Maybe someone else know the answer of this. 也许其他人知道这个答案。

You are using same array arr in different elements. 您在不同的元素中使用相同的数组arr。 If you really need this behavior it's better trying to clone the array arr instead of assign it to many components. 如果您确实需要此行为,最好尝试克隆数组arr,而不是将其分配给许多组件。 Try not using same array arr I think this is the problem. 尝试不使用相同的数组arr,我认为这是问题所在。 Some elements on flex 3 must not be shared in different visual components. Flex 3上的某些元素一定不能在不同的视觉组件中共享。 I prefer to assign properties on repeated components in repeat event instead of doing it online. 我更喜欢在重复事件中为重复的组件分配属性,而不是在线进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM