views:

35

answers:

2

As far as I can tell, the template feature in XUL doesn't allow you to load JSON data into your listbox/tree/etc. element. -- it only supports XML and RDF. The closest thing I found to an indication that it might someday support JSON, is the comments on this blog post from 2007, saying that there was a bug filed. But the bug in question is marked RESOLVED FIXED and JSON is still not supported. So I guess my options are:

  1. Get the data I need in XML, and display it using templates.
  2. Get the data in JSON, and display it by direct DOM manipulation.
  3. Use one of these third-party templating solutions.

So my question is, am I correct that templates don't support JSON? If not, where is that feature documented? If I am correct, what should I consider when choosing among the above three options?

A: 

I'm not sure about JSON in XUL templates, however I'd suggest option 2, given the ease with which JSON is used within the browser.

From Firefox 3.5, you can just do var obj = JSON.parse(xhr.responseText);

Ivan Kruchkoff
I actually was doing that for a little while and it seemed to make everything go really slowly. It looks like we're going to use XML to transfer data (yes, despite the angle bracket tax...) although I agree that JSON is very easy to use. It turns out that option 4, writing my own nsITreeView, is much less painful than I expected, so that is what I'm doing, at least for right now.
MatrixFrog
A: 

It turns out that writing your own custom object that implements nsITreeView is a lot simpler than I expected, and makes everything seem nice and fast.

MatrixFrog