3

我在创建新节点时使用 contextmenu 插件,然后有我自己的函数来使用 ajax 回发创建新节点。

$("#tree").jstree({
            //....

            "plugins": ["themes", "json_data", "crrm", "contextmenu", "dnd", "ui", "cookies"]
})
//...
.bind("create.jstree", function (e, data) {
             //...
             $.ajax({
                    type: "POST",
                    //...
                    });
});

单击“创建”时,我想将“新节点”的默认标签更改为“新文件夹”。任何帮助,将不胜感激。

4

5 回答 5

13

这是在 jsTree v.3 中更改字符串的方法。请注意,这与早期版本不同,因为关键是您要更改的文本('New node'而不是new_node):

$("#content_tree").jstree({
    core: {
        strings : {
            'New node': 'Your Text'
        }
    }
});
于 2014-10-01T19:34:23.973 回答
3

以下是更改上下文菜单选项的方法

$("#tree").jstree({
"plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"],
"contextmenu": {
    "items": function ($node) {
        return {
            "Create": {
                "label": "New Folder",
                "action": function (obj) {
                    this.create(obj);
                }
            }
        };
    }
}
});

更新

您可以在 jquery.jstree.js 文件中找到这部分

if(!js.data) { js.data = this._get_string("new_node"); }

将此部分更改为

if(!js.data) { js.data = this._get_string("new folder"); }
于 2013-02-15T04:49:34.687 回答
1

根据文档,您只需在核心设置中定义字符串参数。

例如:

        $("#content_tree").jstree({
            core: {
                animation: 100,
                strings : { loading : "Loading ...", new_node : "New folder" }
            },
            "plugins" : [ "themes", "html_data"]
        });
于 2013-04-24T22:15:35.973 回答
1

create_node初始化事件后添加行

data.node.text = 'My Custom Name';

例子:

$('#selector').jstree( ... ).on('create_node.jstree', function (e, data) {

   data.node.text = 'My Custom Name';

   ...

});

添加

于 2014-10-23T23:48:59.140 回答
0

感谢您的帮助。我将新节点更改为默认设置中 jquery.jstree.js 文件中的新文件夹,它可以正常工作。再次感谢你。

$.jstree.plugin("core", {
        __init : function () {
            this.data.core.locked = false;
            this.data.core.to_open = this.get_settings().core.initially_open;
            this.data.core.to_load = this.get_settings().core.initially_load;
        },
        defaults : { 
            html_titles : false,
            animation   : 500,
            initially_open : [],
            initially_load : [],
            open_parents : true,
            notify_plugins : true,
            rtl         : false,
            load_open   : false,
            strings     : {
                loading     : "Loading ...",
                new_node    : "New folder",
                multiple_selection : "Multiple selection"
            }
        },
于 2013-02-19T07:09:18.353 回答