在此项目渲染器中创建带有删除按钮的下拉列表
我使用 Flex 4.5,喜欢创建自定义下拉列表。事实上,我想在下拉列表的每一行中显示一个标签和一个删除按钮。 目标是通过单击删除按钮删除该行。 这看起来很简单,但我不知道如何做到这一点。
感谢您的帮助
I works with Flex 4.5 and I like to create a custom dropdownlist. Indeed, I'd like to show in each line on my dropdownlist a label and a delete button.
The goal is to delete the line on click to delete button.
This look like simple, but I don't found how to do that.
Thanks for helping
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您必须跳过一些步骤,因为 DropDownList 会阻止触发来自 ItemRenderer 内的对象的任何
MouseEvent.CLICK
。首先要做的事情是:您需要一个自定义事件才能使其工作。带有您的物品或至少其索引的一个。例如:
然后您创建一个带有“删除”按钮的自定义 ItemRenderer,该按钮将调度此事件。
这里重要的是您捕获按钮的 MOUSE_DOWN 事件,因为它的 CLICK 事件不会触发(如前所述)。 ItemRenderer 的
owner
属性引用其子级的 List。现在是最后一块拼图了。这是带有自定义 ItemRenderer 的 DropDownList:
以下是您如何侦听该自定义事件并删除所选项目:
因为我们捕获了 MOUSE_DOWN 而不是 CLICK,所以
myDropDownList.selectedIndex
属性仍将位于先前所选的项目处(如果没有选择,则为 -1)。这就是我们需要自定义事件的原因,因为没有其他方法可以知道您要删除哪个项目。You have to jump through a few hoops for this one because DropDownList prevents any
MouseEvent.CLICK
from an object inside an ItemRenderer from being fired.First things first: you will need a custom event for this to work. One that carries your item or at least its index. e.g.:
Then you create a custom ItemRenderer with a 'delete' Button that will dispatch this event.
Important here is that you catch the MOUSE_DOWN event of the Button, since its CLICK event doesn't fire (as mentioned before). The
owner
property of the ItemRenderer refers to the List it is a child of.Now the last piece of the puzzle. Here's your DropDownList with custom ItemRenderer:
And here's how you listen for that custom event and remove the selected item:
Because we caught the MOUSE_DOWN instead of CLICK the
myDropDownList.selectedIndex
property will still be at the previously selected item (or -1 if none was selected). This is why we needed the custom event, because there was no other way of knowing which is the item you want to remove.