【发布时间】:2011-04-16 22:04:25
【问题描述】:
所以我有一个使用 XUL 创建的项目树。当我从此树中选择项目并单击查看按钮时,我想显示有关所选项目的信息。我按如下方式操作,但按钮根本不起作用。
为树分配一个id:
<tree id="assetList" flex="1" multiple="false">
然后我在按钮上附加一个函数:
<button id="view-button" align="right" class="dialog" label="View" oncommand="view()" />
然后我有如下写的函数视图:
function view(){
var tree = document.getElementById("assetList");
var items = tree.selectedItems;
if(items.length == 0)
alert("No item was selected");
else if(items.length > 1)
alert("Please select one item at a time");
else{
txt = items.getAttribute('id'); //it's just for testing right now
alert(txt);
}
}
即使我没有选择任何内容并单击查看,也不会触发警报消息。我做错了什么?以及如何解决?
谢谢
【问题讨论】:
-
所以我将 seltype="single" 添加到
以便用户一次只能选择 1 行。我使用 tree.currentIndex 来获取用户选择的位置。但是,我找不到任何函数来检索该位置的元素。有人可以给我一些提示吗?
标签: javascript tree xul onselect