【问题标题】:Flex List selectedIndex is -1?弹性列表 selectedIndex 是 -1?
【发布时间】:2013-10-12 18:40:25
【问题描述】:

我的 flex 应用程序中有一个列表,其中包含 requiresSelection = falseallowMultipleSelection = true。我在获取所选索引时遇到了问题:它返回为-1。我需要知道在列表中选择了哪些 Items 才能使我的应用程序正常工作。我花了几个小时在网上寻找并尝试不同的方法来让它发挥作用。提前感谢您的帮助。

完整列表代码:

<s:List id="list1" x="10" y="35" width="100" height="400" allowMultipleSelection="true" click="list1Click(event)" 
contentBackgroundColor="#696969" dataProvider="{list1Array}" itemRenderer="assets.ListSkinClass"/>

【问题讨论】:

    标签: list apache-flex actionscript flex4 flash-builder


    【解决方案1】:

    selectedIndex 值为 -1 表示未选择任何内容。

    如果你有allowMultipleSelection = true;然后 selectedIndex 将返回最后选择的项目。

    您可以使用 selectedIndices 获取当前选择的所有项目的数组。

    【讨论】:

    • 嗨,一旦选择了一个项目,我就会得到列表的 selectedIndex 。如果我选择了一个项目,则 selectedIndex 等于 -1,但如果我选择两个项目,那么它将正常工作...
    • 另外,我尝试过使用 selectedIndices 但是当我只选择一项时,selectedIndices 返回 null/""。
    • @RMK-Jacob 那么您的代码有其他问题,根据您提供的小代码无法确定。否则,您在 List 代码中发现了一个错误。您能否提供一个完整的可运行代码示例来演示该问题?
    • @RMK-Jacob 我最好的猜测(根据提供的代码)是,您正在尝试访问selectedIndex,然后通过侦听click 事件实际更改它。尝试监听 change 事件。
    猜你喜欢
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多