开发者

Using JSON in XUL <template>s

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开发者_StackOverflow 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜