XUL 中的列表操作
我正在尝试找出一种简单的方法来编辑/添加/删除 XUL 列表中的项目。我最初的想法是有一个单独的文件来处理所有这些,但我不确定如何用另一个文件影响主 XUL。到目前为止,我的列表如下所示:
<?xml version = "1.0"?>
<!DOCTYPE window>
<window title = "Hello"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
<script>
</script>
<listbox id = "mainList" flex = "1">
<listhead>
<listheader label = "Album Name"/>
<listheader label = "Artist"/>
<listheader label = "Year"/>
<listheader label = "Sales"/>
<listheader label = "Rating"/>
<listheader label = "Genre"/>
<listheader label = "Edit" />
<listheader label = "Delete"/>
</listhead>
<listitem id = "1">
<listcell label = "OK Computer"/>
<listcell label = "Radiohead"/>
<listcell label = "1997"/>
<listcell label = "Platinum"/>
<listcell label = "5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit" oncommand= "editItem()"/>
<button label = "Delete" oncommand = "deleteItem()"/>
</listitem>
<listitem>
<listcell label = "The Moon and Antarctica"/>
<listcell label = "Modest Mouse"/>
<listcell label = "2000"/>
<listcell label = "Gold"/>
<listcell label = "4.5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
<listitem>
<listcell label = "Pinkerton"/>
<listcell label = "Weezer"/>
<listcell label = "1996"/>
<listcell label = "Gold"/>
<listcell label = "5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
<listitem>
<listcell label = "Helplessness Blues"/>
<listcell label = "Fleet Foxes"/>
<listcell label = "2011"/>
<listcell label = "Gold"/>
<listcell label = "4/5"/>
<listcell label = "Folk Pop"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
</listbox>
</window>
非常简单,但我对需要什么 javascript 才能使按钮实际工作感到困惑。理想情况下,我希望有一个“添加”按钮,该按钮将打开一个新窗口,其中每列都有空白字段,然后将新行添加到列表中。实现这一目标的最佳方法是什么?
I'm trying to figure out an easy way to edit/add/delete items on a list in XUL. My initial thought is to have a separate file to handle all of this but I'm not sure on how to affect the main XUL with another file. So far my list looks like:
<?xml version = "1.0"?>
<!DOCTYPE window>
<window title = "Hello"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
<script>
</script>
<listbox id = "mainList" flex = "1">
<listhead>
<listheader label = "Album Name"/>
<listheader label = "Artist"/>
<listheader label = "Year"/>
<listheader label = "Sales"/>
<listheader label = "Rating"/>
<listheader label = "Genre"/>
<listheader label = "Edit" />
<listheader label = "Delete"/>
</listhead>
<listitem id = "1">
<listcell label = "OK Computer"/>
<listcell label = "Radiohead"/>
<listcell label = "1997"/>
<listcell label = "Platinum"/>
<listcell label = "5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit" oncommand= "editItem()"/>
<button label = "Delete" oncommand = "deleteItem()"/>
</listitem>
<listitem>
<listcell label = "The Moon and Antarctica"/>
<listcell label = "Modest Mouse"/>
<listcell label = "2000"/>
<listcell label = "Gold"/>
<listcell label = "4.5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
<listitem>
<listcell label = "Pinkerton"/>
<listcell label = "Weezer"/>
<listcell label = "1996"/>
<listcell label = "Gold"/>
<listcell label = "5/5"/>
<listcell label = "Alternative Rock"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
<listitem>
<listcell label = "Helplessness Blues"/>
<listcell label = "Fleet Foxes"/>
<listcell label = "2011"/>
<listcell label = "Gold"/>
<listcell label = "4/5"/>
<listcell label = "Folk Pop"/>
<button label = "Edit"/>
<button label = "Delete"/>
</listitem>
</listbox>
</window>
Pretty simple but I'm confused about what javascript I need to make the buttons actually work. Ideally I'd want to have an Add button that will open a new window with blank fields for each of the columns, and then add the new row to the list. What would be the best way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用常规 DOM 操作函数。动态添加项目时,如果您在可以克隆和修改的地方有一个“模板”,那么会更容易,例如:
然后您可以像这样添加新项目:
更改现有项目的文本是类似的。您必须从某个地方获取新文本 - 添加文本字段进行编辑是您的责任,但是该列表没有内置的编辑功能。
删除项目显然更简单:
You use the regular DOM manipulation functions. When adding items dynamically it is easier if you have a "template" somewhere that you can clone and modify, e.g.:
You can then add a new item like this:
Changing text of an existing item is similar. You have to get the new text from somewhere - adding text fields for editing is your responsibility however, the list has no built-in editing capabilities.
Removing items is obviously simpler: