tree的点击事件

xml 代码
  1. <?xml version="1.0"?>  
  2.   
  3. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>  
  4.   
  5. <window id="treeRDF" title="RDF Tree"  
  6.         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">  
  7. <script  src="script/tree.js" />  
  8. <label value="Things in my house:"/>  
  9.   
  10. <tree flex="1" width="450" height="300" seltype="single" onselect="onAccountClick('tree2')" id="tree2"  
  11.       datasources="things.rdf" ref="urn:things:root">  
  12.   
  13.   <treecols>  
  14.     <treecol id="name" label="Name" primary="true" flex="1"/>  
  15.     <treecol id="material" label="Material" flex="1"/>  
  16.   </treecols>  
  17.   
  18.   <template>  
  19.     <treechildren>  
  20.       <treeitem uri="rdf:*">  
  21.         <treerow>  
  22.           <treecell label="rdf:http://www.xulplanet.com/rdf/example#name"/>  
  23.           <treecell label="rdf:http://www.xulplanet.com/rdf/example#material"/>  
  24.         </treerow>  
  25.       </treeitem>  
  26.     </treechildren>  
  27.   </template>  
  28. </tree>  
  29.   
  30. </window>  
这是xul页面,我是通过rdf传数据的,它的rdf文件是这样的,文件名叫things.rdf
xml 代码
  1. <?xml version="1.0"?>  
  2.   
  3. <RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  
  4.          xmlns:things="http://www.xulplanet.com/rdf/example#">  
  5.   
  6.    <RDF:Description about="urn:things:kitchen" things:name="Kitchen"/>  
  7.    <RDF:Description about="urn:things:bedroom" things:name="Bedroom"/>  
  8.    <RDF:Description about="urn:things:basement" things:name="Basement"/>  
  9.   
  10.    <RDF:Description about="urn:things:toaster" things:name="Toaster" things:material="Aluminum"/>  
  11.    <RDF:Description about="urn:things:sink" things:name="Sink" things:material="Steel"/>  
  12.    <RDF:Description about="urn:things:spicerack" things:name="Spice Rack" things:material="Cedar"/>  
  13.    <RDF:Description about="urn:things:bed" things:name="Bed" things:material="Oak"/>  
  14.    <RDF:Description about="urn:things:lavalamp" things:name="Lava Lamp" things:material="Lava"/>  
  15.    <RDF:Description about="urn:things:junk" things:name="Junk" things:material="Unknown"/>  
  16.    <RDF:Description about="urn:things:morejunk" things:name="More Junk" things:material="Unknown"/>  
  17.    <RDF:Description about="urn:things:coffin" things:name="Coffin" things:material="Pine"/>  
  18.   
  19.   <RDF:Seq about="urn:things:root">  
  20.     <RDF:li>  
  21.       <RDF:Seq about="urn:things:kitchen">  
  22.         <RDF:li resource="urn:things:toaster"/>  
  23.         <RDF:li resource="urn:things:sink"/>  
  24.         <RDF:li resource="urn:things:spicerack"/>  
  25.        </RDF:Seq>  
  26.        <RDF:Seq about="urn:things:bedroom">  
  27.          <RDF:li resource="urn:things:bed"/>  
  28.          <RDF:li resource="urn:things:lavalamp"/>  
  29.        </RDF:Seq>  
  30.        <RDF:Seq about="urn:things:basement">  
  31.          <RDF:li resource="urn:things:junk"/>  
  32.          <RDF:li resource="urn:things:morejunk"/>  
  33.          <RDF:li resource="urn:things:coffin"/>  
  34.        </RDF:Seq>  
  35.     </RDF:li>  
  36.   </RDF:Seq>  
  37.   
  38. </RDF:RDF>  

js代码:function onAccountClick(treeID)
{
  var tree =  document.getElementById(treeID);
    var selection = tree.contentView.getItemAtIndex( tree.currentIndex );
    var foo = selection.firstChild.firstChild.getAttribute("label");
    alert(foo);
}

这里要注意的是tree.contentView.getItemAtIndex( tree.currentIndex );
不是所有的tree都有getItemAtIndex这个方法,只有Content Tree和RDF Content Tree这两种类型的树才有,你可以用alert(tree.contentView)就可以知道是哪种类型的树了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值