【问题标题】:jstree get new json data from treejstree 从树中获取新的 json 数据
【发布时间】:2015-02-21 11:22:43
【问题描述】:

我用以下数据创建了一棵树。 在这个过程之后,我在菜单之间做了一个拖放过程。结果,我的菜单结构发生了变化。 我想导出与我的第一个数据具有相同结构的新 JSON 数据。 如何从树中获取数据?请帮帮我。

我试过这段代码,但是这个导出的 JSON 非常复杂。我不会喜欢我的第一个数据格式。

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

菜单的第一个状态:

菜单的最后状态:

// 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

【问题讨论】:

    标签: javascript json tree getjson jstree


    【解决方案1】:

    我找到了从树中获取 json 的最简单方法;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多