Jstree在创建新节点时如何更改“新节点”标签?

Jstree在创建新节点时如何更改“新节点”标签?,jstree,Jstree,我在创建新节点时使用contextmenu插件,然后使用ajax post back创建新节点,这是我自己的功能 $("#tree").jstree({ //.... "plugins": ["themes", "json_data", "crrm", "contextmenu", "dnd", "ui", "cookies"] }) //... .bind("create.jstree", function (e, data) {

我在创建新节点时使用contextmenu插件,然后使用ajax post back创建新节点,这是我自己的功能

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

            "plugins": ["themes", "json_data", "crrm", "contextmenu", "dnd", "ui", "cookies"]
})
//...
.bind("create.jstree", function (e, data) {
             //...
             $.ajax({
                    type: "POST",
                    //...
                    });
});
我想在单击“创建”时将“新建节点”的默认标签更改为“新建文件夹”。
任何帮助都将不胜感激。

以下是更改关联菜单选项的方法

$("#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"); }

谢谢你的帮助。我在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"
            }
        },

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

例如:

        $("#content_tree").jstree({
            core: {
                animation: 100,
                strings : { loading : "Loading ...", new_node : "New folder" }
            },
            "plugins" : [ "themes", "html_data"]
        });

下面介绍如何在JSTreeV.3中更改字符串。注意:这与早期版本不同,因为键是要更改“新节点”而不是“新节点”的文本:


在初始化创建节点事件后添加行

例如:

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

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

   ...

});

添加

谢谢您的回答。这将在上下文菜单中将“创建”更改为“新建文件夹”。但我的意思是,当您从上下文菜单中选择“创建”时,它会创建一个节点,并在默认情况下将其标记为“新节点”。我要做的是将此标签从“新节点”更改为“新文件夹”或其他任何内容。还有其他解决方案吗?我不确定最佳解决方案,但这似乎有效。只需在jquery.jstree.js中搜索新节点,并将名称从new_node更改为new Folder。如果您正在阅读另一篇SO文章,您可以像这样通过上下文菜单动态加载它,我对未格式化的代码表示歉意:操作:函数数据{var inst=$.jstree.referencedata.reference,obj=inst.get_nodedata.reference;inst.create_nodeobj,{},last,function new_node{new_node.data={type:file};new_node.text=Unamed Document;setTimeoutfunction{inst.editnew node;},0; };
data.node.text = 'My Custom Name';
$('#selector').jstree( ... ).on('create_node.jstree', function (e, data) {

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

   ...

});