2013-02-11 69 views
3

我在创建新节点时使用contextmenu插件,然后使用自己的函数来创建使用ajax回发的新节点。Jstree如何在创建新节点时更改“新节点”标签?

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

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

我想在点击“创建”时将“New node”的默认标签更改为“New folder”。 任何帮助,将不胜感激。

回答

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"); } 
+0

谢谢您的回答。这将在上下文菜单中将“创建”更改为“新建文件夹”。但我的意思是,当你从contextmenu中选择create时,它会创建一个节点并默认将其标记为'new node'。我想要做的是将此标签从“新节点”更改为“新文件夹”或其他任何内容。其他解决方案? – user1684931 2013-02-18 02:13:35

+0

我不确定最佳的灵魂,但这似乎工作。只需在jquery.jstree.js中搜索新节点,并将名称从new_node更改为New Folder。 – jeev 2013-02-18 04:35:45

+0

从另一篇SO文章开始,你可以通过这样的上下文菜单动态加载它(并且我对未格式化的代码表示歉意):''action“:function(data)var inst = $ .jstree.reference data.reference), obj = inst.get_node(data.reference); (函数(){inst());(){}(){} {} {} { .edit(new_node);},0); });' – codermjb 2016-04-01 02:52:38

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" 
      } 
     }, 
1

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

例如:

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

下面是如何改变字符串jsTree第3节。请注意,这是从早期版本不同,因为关键是要改变(的'New node'代替new_node)文字:

$("#content_tree").jstree({ 
    core: { 
     strings : { 
      'New node': 'Your Text' 
     } 
    } 
}); 
1

添加行后初始化create_node事件

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

例如:

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

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

    ... 

}); 

add