如何对列表项双击做出反应并为每个列表项添加上下文菜单?
我的 xul 中有 listbox
元素。 listitem
元素会动态添加到此处。
我如何:
- 双击每个
listitem
做出反应? - 为每个列表项实现上下文菜单?
在 listitem
创建期间,我知道添加到其中的每条记录的唯一 ID(数字)。理想情况下,当调用双击函数并且选择上下文菜单项时,我应该获得此 id(并且用户不应该看到它)。
I have listbox
element in my xul. listitem
elements are added there dynamically.
How can I:
- react on double click on each
listitem
? - implement context menu for each
listitem
?
During listitem
s creation, I know unique id (numeric) of each record added there. Ideally when double click function is called and when context menu item is chosen, I should get this id (and it shouldn't be visible to the user).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事件冒泡意味着您可以在
元素上注册事件处理程序。event.target
允许您查找
元素:这假设您在添加之前已将
recordId
属性添加到列表项中将他们列入名单。上下文菜单的工作方式类似(您将
context="..."
属性添加到
),不同之处在于上下文菜单通常在菜单的popupshowing
事件。此事件的目标是上下文菜单本身,因此它不能帮助您找到列表项。但是,有一个menupopup.triggerNode()
属性< /a> (已弃用的document.popupNode
的现代替代品)可以让您完成这项工作:Events bubble which means that you can register your event handler on the
<listbox>
element.event.target
allows you to find the<listitem>
element:This assumes that you've added
recordId
attributes to your list items before adding them to the list.Things work similarly with context menus (you add a
context="..."
attribute to the<listbox>
), with the difference that context menus are usually initialized in the menu'spopupshowing
event. The target of this event is the context menu itself so it doesn't help you find the list item. However, there is amenupopup.triggerNode()
property (the modern alternative to the deprecateddocument.popupNode
) that lets you do the job: