use*_*266 13 javascript tree json getjson jstree
我创建了一个包含以下数据的树.在这个过程之后,我在菜单之间进行了拖放过程.结果我的菜单结构被更改了.我想导出与我的第一个数据具有相同结构的新json数据.如何从树中获取数据?请帮助我.
我试过这段代码,但这个导出非常复杂的json.我想要我的第一个数据格式.
var v = $('#data').jstree(true).get_json();
var mytext = JSON.stringify(v);
alert(mytext);
Run Code Online (Sandbox Code Playgroud)
第一个菜单状态:
菜单的最后状态:
// 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
Run Code Online (Sandbox Code Playgroud)
use*_*266 35
我找到了从树上获取json的最简单方法;
var v = $('#data').jstree(true).get_json('#', {flat:true})
var mytext = JSON.stringify(v);
alert(mytext);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17445 次 |
| 最近记录: |