Flex 4 - 选择并选择取消选择中的相同项目按下鼠标

发布于 2024-10-07 18:04:38 字数 585 浏览 0 评论 0原文

在 Flex 4 中,我有一个带有项目渲染器的 Spark List 组件。 我想通过单击列表中的一个项目来选择它,并通过单击同一选定项目来取消选择它。就像一个开/关开关。

我的项目渲染器具有以下状态:

<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>

所以我尝试向项目渲染器添加一个单击事件侦听器:

private function selectUnSelect():void {
if (currentState == 'selected') currentState = 'normal';
else currentState = 'selected';

}

具有尴尬的行为...即使在选定状态下再次单击该项目,该项目仍保持选中状态。

考虑使用列表组件,而不使用命令(在 Mac 上)或 Windows 上的控制按钮。

In Flex 4, I have a Spark List component with item renderers.
I would like to select an item in the List by clicking on it, and deselect it also, by clicking on the same selected item. Like an on/off switch.

My item renderer has the following states:

<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>

so I tried to add a click event listener to the item renderer with:

private function selectUnSelect():void {
if (currentState == 'selected') currentState = 'normal';
else currentState = 'selected';

}

with an awkward behaviour... where the item stay selected even after clicking it again in the selected state.

Think of using the List component without the Command (on mac) or the Control button on windows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪 2024-10-14 18:04:39

我不会让项目渲染器设置其状态,而是对列表本身进行操作。让项目渲染器在单击时调度一个事件,其中包含项目渲染器的数据,然后为该事件添加侦听器(在扩展 List 的组件中,或在包含列表的组件中)。然后,您可以检查数据是否与列表的任何选定项目匹配。如果没有,则将该项目追加到 selectedItems 中。如果是这样,请将其从 selectedItems 中删除。希望有帮助。

Rather than have the item renderer set its state, I would operate on the List itself. Have your item renderer dispatch an event when it is clicked that includes the data of the item renderer, then add a listener for that event (either in a component that extends List, or in the component that contains your list). You can then check if the data matches any of your List's selectedItems. If not, append the item to the selectedItems. If so, remove it from the selectedItems. Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文