简体   繁体   English

具有XUL和Javascript的OnSelect处理程序

[英]OnSelect handler with XUL and Javascript

So I have a tree of items created using XUL. 因此,我有一棵使用XUL创建的项目树。 When I select item from this tree and click a View button I want to display information about the selected item. 当我从该树中选择项目并单击“查看”按钮时,我要显示有关所选项目的信息。 I do it as below but the button does not work at all. 我按以下方式进行操作,但是该按钮根本不起作用。

Assign an id for the tree: 为树分配一个ID:

<tree id="assetList" flex="1" multiple="false">

Then I attach a function to the button: 然后我将一个函数附加到按钮:

<button id="view-button" align="right" class="dialog" label="View" oncommand="view()" />

Then I have function view written as bellow: 然后我将函数视图写为波纹管:

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);
  }
}

Even when I don't select anything and click view the alert message is not fired. 即使我没有选择任何内容并单击查看,警报消息也不会触发。 What did I do wrong? 我做错了什么? and How can I fix it? 以及如何解决?

Thanks 谢谢

I figured out how to do this. 我想出了怎么做。 I can use getItemAtIndex(tree.currentIndex). 我可以使用getItemAtIndex(tree.currentIndex)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM