我有37种不同的节点类型.我正在尝试实现拖放.这有效但我需要确切地限制可以拖动哪些类型以及可以删除它们的位置.遗憾的是,我在文档中找不到任何有用的信息(http://www.jstree.com/documentation).
到目前为止,我尝试了三种方法:
first:根据节点类型在drag_check回调中定义true或false的返回值:
$("#demo1").jstree({
"dnd" : {
"drag_check" : function () {
Run Code Online (Sandbox Code Playgroud)
第二种:绑定到prepare_move.jstree事件并根据节点类型返回true或false值:
.bind("prepare_move.jstree", function (e, data) {
if (data.rslt.o.attr("typ") === "tpop") {
Run Code Online (Sandbox Code Playgroud)
第三:使用类型插件并在那里定义有效的子代:
$("#tree").jstree( {
"types": {
"type_attr": "typ",
"valid_children": ["ap_ordner_pop", "ap_ordner_apziel", "ap_ordner_erfkrit", "ap_ordner_apber", "ap_ordner_ber", "ap_ordner_beob", "iballg", "ap_ordner_ibb", "ap_ordner_ibartenassoz"],
"types": {
"ap_ordner_pop": {
"valid_children": "pop"
},
"pop": {
"valid_children": ["pop_ordner_tpop", "pop_ordner_popber", "pop_ordner_massnber"],
"new_node": "neue Population"
},
"pop_ordner_tpop": {
"valid_children": "tpop"
}
Run Code Online (Sandbox Code Playgroud)
但我几乎可以在任何地方丢弃大多数节点.怎么办呢?或者你能指出一个很好的例子吗?
非常感谢帮助.
如何使用复选框插件删除jstree中的文件夹图标?
$('#div').jstree({
"ui": {
"theme_name": "checkbox"
},
"theme" : { "icons": false },
"json_data": {
"ajax": {
"type": "POST",
"url": "@Url.Action("Tree")"
}
},
"plugins": ["json_data", "checkbox", "ui", "themes"]
});
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但它显示复选框图标以及文件夹图标.
所以,我的问题.我用一些数据初始化了我的树:
$('#tree').jstree({
'core' : {
'data' : [
'Simple root node',
{
'id' : 'node_2',
'text' : 'Root node with options',
'state' : { 'opened' : true, 'selected' : true },
'children' : [ { 'text' : 'Child 1' }, 'Child 2']
}
]
});
Run Code Online (Sandbox Code Playgroud)
但经过一些动作后,我想用新数据重绘树.我尝试使用API中的刷新和重绘方法,但它没有成功.
你能给我建议,如何刷新树(没有销毁 - >创建新实例(它可以工作,但会影响性能))?
昨天开始使用jQuery和jsTree插件,并通过对servlet的AJAX调用成功加载树.现在,我想在加载后让树打开所有节点,所以我在ajax属性中添加了一个成功函数.但是,我似乎无法使open_all()方法正常工作.我对使用jQuery非常陌生,所以我猜这很简单,我做错了.
Firebug没有显示任何错误,这些错误排除了输入错误的方法名称的愚蠢错误.我检查了文档,我认为我正在按照我所读的内容正确地完成所有工作.树正确加载,但在页面加载后没有打开所有节点.
我在Firefox 3.6.8上使用jQuery 1.4.2和jsTree 1.0rc2.
这是我用来加载树并尝试打开树中所有节点的代码:
// Create the tree object
$("td#modelXML").jstree({
core : { "animation" : 0 },
//xml_data : {"data" : "" + xml, "xsl" : "nest"},
xml_data : {"ajax" :
{"url" : "servlet/GetModelHierarchy",
"type" : "post", "data" : { modelId : "" + modelId} },
"xsl" : "nest",
"success" : function(){
$(this).open_all(-1);
}
},
themes : {"theme" : "classic", "dots" : true, "icons" : true},
types : {
"types" : {
"category" : {
"valid_children" : …Run Code Online (Sandbox Code Playgroud) 我正在使用jsTree jQuery插件,并希望在用户双击节点时执行代码.
我似乎无法让它发挥作用.我发现了一些关于某个ondblclk事件的文档,但它没有触发.
browser.jstree(
{
plugins: ["themes", "json_data", "ui", "cookies"],
callback:
{
ondblclk: function (node, tree) {
if (!thisReportBrowserthis._isFoldersOnly) {
var f = node;
}
}
}
}
);
Run Code Online (Sandbox Code Playgroud)
如何使用jstree处理双击事件?
我正在使用JQuery插件jsTree,http://www.jstree.com/ 我可以使用以下方法扩展整个树:
$("#tree").jstree("open_all");
Run Code Online (Sandbox Code Playgroud)
还有一个特定的节点:
$("#tree").jstree("open_node", $('#childNode'));
Run Code Online (Sandbox Code Playgroud)
我很难打开树的一个分支,打开分支打开它很好,但如果它有一个就不打开它的父.
有没有人用jsTree成功完成这项工作?如果您需要更多信息,请告诉我.
谢谢
EEF
我正在尝试编写一个在jsTree上打开特定节点的函数,但我遇到的问题是在从ajax调用加载基础树之前执行该函数.如何判断我的jstree数据是否已加载并等待加载完毕.以下是我尝试使用的功能.
function openNodes(tree, nodes) {
for (i in nodes) {
$('#navigation').jstree("open_node", $(nodes[i]));
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下命令加载我的初始树
$("#navigation").jstree({
"json_data": {
"ajax": {
"url": function(node) {
var url;
if (node == -1) {
url = "@Url.Action("BaseTreeItems", "Part")";
} else {
url = node.attr('ajax');
}
return url;
},
"dataType": "text json",
"contentType": "application/json charset=utf-8",
"data": function(n) { return { id: n.attr ? n.attr("id") : 0, ajax: n.attr ? n.attr("ajax") : 0 }; },
"success": function() {
}
}
},
"themes": { "theme": "classic" }, …Run Code Online (Sandbox Code Playgroud) 我正在使用jsTree 3.0.0,我需要通过以下方式之一修改上下文:
我尝试了几种方法但没有任何效果.例如,Uncaught TypeError: Object [object global] has no method 'create'当我单击"创建"时,这将返回.
"contextmenu":{
"items": function($node) {
return {
createItem : {
"label" : "Create New Branch",
"action" : function(obj) { this.create(obj); alert(obj.text())},
"_class" : "class"
},
renameItem : {
"label" : "Rename Branch",
"action" : function(obj) { this.rename(obj);}
},
deleteItem : {
"label" : "Remove Branch",
"action" : function(obj) { this.remove(obj); }
}
};
}
},
Run Code Online (Sandbox Code Playgroud)
如果我尝试添加一个项目,如下一个示例所示,我将松开默认菜单项:
items : {
"create_folder" : {
"separator_before" : …Run Code Online (Sandbox Code Playgroud) 我正在使用带有复选框主题的jsTree jQuery插件.有谁知道如何使用表格帖子获取所选值?
谢谢!
我一直在尝试获取在jsTree中选择的节点的文本.我能够填充树并触发onSelect事件,但我找不到单击的节点.我在网上看到了data.rslt.obj.attr("data")用于获取文本的示例,但这对我来说是未定义的.此外,当我尝试使用所选节点时,.jstree('get_selected')我无法在对象中的任何位置找到节点文本.如何获取节点文本?
这是我的onSelect回调函数:
function onSelect(event, data)
{
// Get the name of the equipment that was selected.
var selected_node = $("#equipment_tree").jstree('get_selected');
var equipment_name = data.rslt.obj.attr("data");
}
Run Code Online (Sandbox Code Playgroud)