简体   繁体   English

jstree从树中获取新的json数据

[英]jstree get new json data from tree

I created a tree with the following data. 我创建了一个包含以下数据的树。 After this process I made a drag drop process between menus.And as a result my menu structre was changed. 在这个过程之后,我在菜单之间进行了拖放过程。结果我的菜单结构被更改了。 I want to export new json data which has same structure with my first data. 我想导出与我的第一个数据具有相同结构的新json数据。 How can I get data from tree ? 如何从树中获取数据? Plese help me. 请帮助我。

I tried this code , but this export very complicated json. 我试过这段代码,但这个导出非常复杂的json。 I want like my first data format. 我想要我的第一个数据格式。

            var v = $('#data').jstree(true).get_json();
            var mytext = JSON.stringify(v);
            alert(mytext);

first state of menu : 第一个菜单状态:

在此输入图像描述

last state of menu : 菜单的最后状态:

在此输入图像描述

// html demo
$('#html').jstree();

// inline data demo



    $(function() {
            var arrayCollection = [
                {"id": "animal", "parent": "#", "text": "Animals"},
                {"id": "device", "parent": "#", "text": "Devices"},
                {"id": "dog", "parent": "animal", "text": "Dogs"},
                {"id": "lion", "parent": "animal", "text": "Lions"},
                {"id": "mobile", "parent": "device", "text": "Mobile Phones"},
                {"id": "lappy", "parent": "device", "text": "Laptops"},
                {"id": "daburman", "parent": "dog", "text": "Dabur Man", "icon": "/"},
                {"id": "Dalmation", "parent": "dog", "text": "Dalmatian", "icon": "/"},
                {"id": "african", "parent": "lion", "text": "African Lion", "icon": "/"},
                {"id": "indian", "parent": "lion", "text": "Indian Lion", "icon": "/"},
                {"id": "apple", "parent": "mobile", "text": "Apple IPhone 6", "icon": "/"},
                {"id": "samsung", "parent": "mobile", "text": "Samsung Note II", "icon": "/"},
                {"id": "lenevo", "parent": "lappy", "text": "Lenevo", "icon": "/"},
                {"id": "hp", "parent": "lappy", "text": "HP", "icon": "/"}
            ];
$('#data').jstree({
    'core' : {
        'check_callback' : true,
        'data' :arrayCollection ,

    },


    "plugins" : ["dnd","wholerow"]
});


});//function

I found the most simple way to get json from tree; 我找到了从树上获取json最简单的方法;

var v = $('#data').jstree(true).get_json('#', {flat:true})
var mytext = JSON.stringify(v);
alert(mytext);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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