简体   繁体   中英

JSON object pass to controller for using it in nested set model

I am making a tree structure with the help of JQuery and Javascript.

The tree has the HTML structure of <ul><li>.. and within every li there is a div that contains two spans.

The first span contains an image and the latter contains the node data.

When the tree is completed I have to pass the complete tree as a JSON object to a controller to use it for assigning the left right values using nested set model.

How can I make the JSON object?

Assign an ID to your <ul> :

<ul id='tree'>
    <li><div><span><img src='...' /></span><span>data</span></div></li>
    ...
</ul>

And then use stringify from the JSON object to get the JSON string:

$(function() {
    var jsonText = JSON.stringify($("#tree")[0]);
});

If you've got JQuery referenced properly, then that should give your the JSON representation of your tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM