jstree从树中获取新的json数据 [英] jstree get new json data from tree
本文介绍了jstree从树中获取新的json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下数据创建了一个树。
在此过程之后,我在菜单之间进行了拖放过程。结果我的菜单结构被更改了。
我想导出与我的第一个数据具有相同结构的新json数据。
如何从树中获取数据?请帮助我。
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. How can I get data from tree ? Plese help me.
我试过这段代码,但这个导出非常复杂的json。我想要的是我的第一种数据格式。
I tried this code , but this export very complicated json. I want like my first data format.
var v = $('#data').jstree(true).get_json();
var mytext = JSON.stringify(v);
alert(mytext);
首页菜单状态:
< a href =https://i.stack.imgur.com/w7Ypq.png =noreferrer>
菜单的最后状态:
// 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
推荐答案
我找到了从树中获取json的最简单方法;
I found the most simple way to get json from tree;
var v = $('#data').jstree(true).get_json('#', {flat:true})
var mytext = JSON.stringify(v);
alert(mytext);
这篇关于jstree从树中获取新的json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文