Configuring jsTree for AJAX

Asked

Viewed 426 times

2

I’m using the plugin jsTree, trying to make you seek the information by AJAX.

In the server side I have four tables on the bench, each one a tree level.

Tabela1
-Tabela2
--Tabela3
---Tabela4

Making the plugin fetch the first level was easy:

$("#tree").jstree({
    core: {
        data: {
            url: "/tabela1.json"
        }
    }
});

But I’m not getting the syntax right to make you search for the other level, at the click of the user.

The two attempts below did not work:

$("#tree").jstree({
    core: {
        data: {
            url: "/tabela1.json",
            data: "/tabela2.json"
        }
    }
});

$("#tree").jstree({
    core: {
        data: {
            url: "/tabela1",
            data: {
                url: "/tabela2.json"
            }
        }
    }
});
  • How are these JSON organized? Sometimes you need a function if you want to control the sublevels. jsTree is relatively simple to use, but I’m not getting what you’re trying to do. It has how to show JSON structures and how you want to organize them?

  • @Bacco It is the first time I use this plugin. I have hidden the names of the tables because they do not suit the problem. But Table1 has many Tables2, which has many Tables3, which has many Tables4. To save bandwidth, the idea is to confirm the user’s click.

  • @Bacco No server side I have routes that return the correct format jsTree asks for, i.e., {'id': 1, 'text': 'Texto'} and accept filter by query string.

  • 1

    I think it is the case that you create your load function then, which is the date parameter of the http://www.jstree.com/docs/json/ nodes at the bottom of the page.

  • @Bacco In this case I have to use $.getJSON and pass the return to the function cb?

  • @user7261 I am studying to make one, when I finish put my code for you.

  • @user7261 follows my logic posted here on Stack. http://answall.com/questions/43477/montar-%C3%A1rvore-jstree/44949#44949

Show 2 more comments

1 answer

1

Because you do not call the tables each one at a time?

var urls = [];
urls[0] = "/tabela1.json";
urls[1] = "/tabela2.json";
urls[2] = "/tabela3.json";
urls[3] = "/tabela4.json";

for(i=0; i < urls.length){
    $("#tree").jstree({
        core: {
            data: {
                url: urls[i];
            }
        }
    });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.