具有自定义json数据的JsTree [英] JsTree with custom json data
问题描述
我在json中有此结构,无法通过请求进行修改.
I have this structure in json I can not be modified by request.
{
"Object": [
{
"url": "http://www.google.com"
}
],
"id": 1,
"name": "Redirection Rule",
"Object": {
"frequency": 1,
"trigger": 1
},
"Object": {
"http": "Redirect Url",
"response": 301
}
}
我需要使用此结构来填充jstree.我只需要使用"id"字段和"name",如何将jstree设置为使用"name"而不是"text"作为节点名称?
I need to use this structure to populate a jstree . I just need to use the "id" fields and "name", how do I set jstree to use "name" instead of "text" as a node name ?
推荐答案
任一:
1)使用jQuery dataFilter
选项(这意味着在core.data
jsTree配置中为dataFilter
定义一个函数),
1) use the jQuery dataFilter
option (this means defining a function for dataFilter
in your core.data
jsTree config),
或
2)将core.data
本身设置为函数,手动发出请求并将其转换为:
2) set core.data
itself to a function, manually make the request and transform it like so:
$('#your-tree').jstree({
core : {
data : function (node, cb) {
$.ajax({ url : ... }).done(function (data) {
cb([{ "id" : data.id, "text" : data.name }])
});
}, ...
您可以在此处找到有关将core.data
设置为功能的更多信息:
https://github.com/vakata/jstree#populating树使用回调函数
You can find more info on setting core.data
to a function here:
https://github.com/vakata/jstree#populating-the-tree-using-a-callback-function
这篇关于具有自定义json数据的JsTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!