mbraak / jqTree

Tree widget for jQuery
https://mbraak.github.io/jqTree/
Apache License 2.0
1.02k stars 177 forks source link

json header #116

Closed burtondav closed 11 years ago

burtondav commented 11 years ago

I'm trying use jqtree using json data.

The json data input starts out with the table name like this:

    {
    locations: [
      {
        label: "Location 1",
        children: [

Instead of starting with first label.

Is there some way to get jqtree to accept this?

Thanks !!

mbraak commented 11 years ago

It depends. Are you loading the data using the data-url option? Or are you using the data option?

data-url: jqTree does not support this; but you can load the data yourself using jquery.ajax

data: I believe you can do the following:

var location_data = {
  locations: [
    { label: 'Location1 '},
    { label: 'Etcetera' }
  ]
};

$('#tree1').tree({
  data: location_data['locations']
});
burtondav commented 11 years ago

This is my jquery (coffeescript) code: $.getJSON "/locations/tree", (data) -> $("#tree1").tree data: data

I'm using jbuilder in Rails. I've changed my json output to now look like this - but, it doesn't work:

{ label: "1st Level", children: [ { label: "2nd Level", children: [

1) Does it need to start with a [ instead of { ???

2) Should I be using the data-url option? 3) I will try your suggestion - thanks!

mbraak commented 11 years ago
  1. Yes, your data should start with [
  2. There is no need to use the data-url option.