具有自定义 json 数据的 JsTree

JsTree with custom json data

我有这个结构json我不能按要求修改。

{
        "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" 作为节点名称?

或者:

1) 使用 jQuery dataFilter 选项(这意味着在 core.data jsTree 配置中为 dataFilter 定义一个函数),

2) 将core.data本身设置为一个函数,手动发出请求并像这样转换它:

$('#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-the-tree-using-a-callback-function