xml 代码
- <?xml version="1.0"?>
- <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
- <window id="treeRDF" title="RDF Tree"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script src="script/tree.js" />
- <label value="Things in my house:"/>
- <tree flex="1" width="450" height="300" seltype="single" onselect="onAccountClick('tree2')" id="tree2"
- datasources="things.rdf" ref="urn:things:root">
- <treecols>
- <treecol id="name" label="Name" primary="true" flex="1"/>
- <treecol id="material" label="Material" flex="1"/>
- </treecols>
- <template>
- <treechildren>
- <treeitem uri="rdf:*">
- <treerow>
- <treecell label="rdf:http://www.xulplanet.com/rdf/example#name"/>
- <treecell label="rdf:http://www.xulplanet.com/rdf/example#material"/>
- </treerow>
- </treeitem>
- </treechildren>
- </template>
- </tree>
- </window>
xml 代码
- <?xml version="1.0"?>
- <RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:things="http://www.xulplanet.com/rdf/example#">
- <RDF:Description about="urn:things:kitchen" things:name="Kitchen"/>
- <RDF:Description about="urn:things:bedroom" things:name="Bedroom"/>
- <RDF:Description about="urn:things:basement" things:name="Basement"/>
- <RDF:Description about="urn:things:toaster" things:name="Toaster" things:material="Aluminum"/>
- <RDF:Description about="urn:things:sink" things:name="Sink" things:material="Steel"/>
- <RDF:Description about="urn:things:spicerack" things:name="Spice Rack" things:material="Cedar"/>
- <RDF:Description about="urn:things:bed" things:name="Bed" things:material="Oak"/>
- <RDF:Description about="urn:things:lavalamp" things:name="Lava Lamp" things:material="Lava"/>
- <RDF:Description about="urn:things:junk" things:name="Junk" things:material="Unknown"/>
- <RDF:Description about="urn:things:morejunk" things:name="More Junk" things:material="Unknown"/>
- <RDF:Description about="urn:things:coffin" things:name="Coffin" things:material="Pine"/>
- <RDF:Seq about="urn:things:root">
- <RDF:li>
- <RDF:Seq about="urn:things:kitchen">
- <RDF:li resource="urn:things:toaster"/>
- <RDF:li resource="urn:things:sink"/>
- <RDF:li resource="urn:things:spicerack"/>
- </RDF:Seq>
- <RDF:Seq about="urn:things:bedroom">
- <RDF:li resource="urn:things:bed"/>
- <RDF:li resource="urn:things:lavalamp"/>
- </RDF:Seq>
- <RDF:Seq about="urn:things:basement">
- <RDF:li resource="urn:things:junk"/>
- <RDF:li resource="urn:things:morejunk"/>
- <RDF:li resource="urn:things:coffin"/>
- </RDF:Seq>
- </RDF:li>
- </RDF:Seq>
- </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)就可以知道是哪种类型的树了.