[Project_owners] More tree questions

Michael Vincent mv_van_rantwijk at yahoo.com
Wed Sep 14 20:47:15 EDT 2005


Michael Nachbaur wrote:
> Michael Vincent wrote:
>> I would like to use sometihng like this:
>>
>> <tree datasources="rdf:null" flags="dont-build-content"..
>>   ../..
>>   <treecell label="rdf:http://multizilla.mozdev.org/rdf#name"
>>             url="rdf:http://multizilla.mozdev.org/rdf#url"/>
>>
>> but I don't know how to read the url/label from that cell, do you?
> 
> Since "dont-build-content" doesn't actually build up the tree cells in 
> the DOM, there's no way to access that information directly. 

Just what I expected (:

> Instead 
> you have to query the RDF Datasource attached to the tree.  For instance:

I can do that, but I'm simply going to add some new <treecell>'s, 
because that way people can also display the columns, in case they want 
to that is.

> <tree id="searchResults" datasources="rdf:null" seltype="single" 
> flags="dont-build-content" ondblclick="openResult()">
>   ...
>   <treeitem uri="rdf:*">
>     ...
>   </treeitem>
> </tree>
> 
> and in your JavaScript:
> 
> var RDF = Components
>   .classes["@mozilla.org/rdf/rdf-service;1"]
>   .getService(Components.interfaces.nsIRDFService);
> 
> function openResult() {
>   var tree = document.getElementById("searchResults");
> 
>   // Gives you the row number for the selected treeitem
>   var selectedIndex = tree.view.selection.currentIndex;
> 
>   // Gives you the RDF resource in the uri="rdf:*" attribute
>   var selectedResource = tree.view.getResourceAtIndex(selectedIndex);
> 
>   // Perform a search against the datasource
>   var urlResource = tree.database.GetTarget(
>     selectedResource,
>     RDF.GetResource("http://multizilla.mozdev.org/rdf#url"),
>     true
>   );
> 
>   if (urlResource instanceof Components.interfaces.nsIRDFResource) {
>     alert("URL is " + urlResource.Value + "\n");
>   } else {
>     alert("Could not find a URL\n");
>   }
> }
> 
> It is possible to build helper functions to ease some of that pain.  I 
> do quite a lot of this sort of thing in my intranet CRM application, so 
> if you want I can send you some of my helpers.

No thank you, I don't need them, thanks anyway,
Michael


More information about the Project_owners mailing list