A. jstree從後台取數據載入後,在前台為什麼展開不了節點,急啊···在線等
$('#tree_2').jstree({
'plugins': ["wholerow", "checkbox", "types"],
'core': {
"themes" : {
"responsive": false
},
'data': [{
"text": "Same but with checkboxes",
"children": [{
"text": "initially selected",
"state": {
"selected": true
}
}, {
"text": "custom icon",
"icon": "fa fa-warning icon-state-danger",
"state": {
"selected": true
}
}, {
"text": "initially open",
"icon" : "fa fa-folder icon-state-default",
"state": {
"opened": true
},
"children": ["Another node"]
}, {
"text": "custom icon",
"icon": "fa fa-warning icon-state-warning"
}, {
"text": "disabled node",
"icon": "fa fa-check icon-state-success",
"state": {
"disabled": true
}
}]
},
"And wholerow selection"
]
},
"types" : {
"default" : {
"icon" : "fa fa-folder icon-state-warning icon-lg"
},
"file" : {
"icon" : "fa fa-file icon-state-warning icon-lg"
}
}
});
B. jstree中想要選中子節點,父節點就會變成選中狀態,需要如何修改。
修改方法:
JQuery
$('#子節點id').parent().attr('id');//通過子元素獲取父元素
js
document.getElementById("子節點id").parentNode.getAttribute("id");
C. 如何用jsTree.js實現結點展開和收攏時圖標的變化
您好,很高興為您解答。
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
<metahttp-equiv="X-UA-Compatible"content="IE=edge"><!--IE使用它所支持的最新版本-->
<metaname="viewport"content="width=device-width,initial-scale=1.0">
<title>tree</title>
<linkhref="../css/bootstrap.min.css"rel="stylesheet">
<linkhref="../css/style.min.css"rel="stylesheet">
<linkhref="../css/font-awesome.min.css"rel="stylesheet">
</head>
<body>
<divid="myTree">
<ul>
<li>Root1</li>
<li>Root2
<ul>
<liid="child1">
<a>child1</a>
<ul>
<li>child1-1</li>
<li>child1-2</li>
</ul>
</li>
<li>child2</li>
<li>child3</li>
</ul>
</li>
<li>Root3</li>
</ul>
</div>
<scriptsrc="../js/jquery.min.js"></script>
<scriptsrc="../js/bootstrap.min.js"></script>
<scriptsrc="../js/jstree.min.js"></script>
<script>
$(function(){
$('#myTree').jstree();
$('#myTree').on("changed.jstree",function(e,data){
console.log(data.selected);
});
$('button').on('click',function(){
$('#myTree').jstree(true).select_node('child1');
$('#myTree').jstree('select_node','child1');
$.jstree.reference('#myTree').select_node('child1');
});
});
</script>
</body>
</html>
如若滿意,請點擊右側【採納答案】,如若還有問題,請點擊【追問】
希望我的回答對您有所幫助,望採納!
~O(∩_∩)O~
D. 如何給JsTree生成的樹的每個節點添加上自定義的右鍵菜單
一個帶有右鍵操作的樹形菜單
$(document).ready(function(){
$.ajaxSetup({cache:false});
$("#browser").tree({
data : {
type : "json",
url : src,
async : true,
async_data : function (NODE) {
return { parent_Id : $(NODE).attr("id") || 0}
}
},
lang:{
loading:"目錄載入中……"
},
rules:
{
draggable : "all" //這個設置可以使得節點進行拖動操作
},
ui:{
context : [ //自定義右鍵操作的可操作內容
{
id : "create",
label : "添加下級目錄", //右鍵彈出菜單的此項操作屏顯字樣
visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); }, //允許節點被右擊時出現操作菜單
icon : "<%=request.getContextPath() %>/css/themes/default/create.png",//右鍵彈出菜單的此項操作圖標
action : function (NODE, TREE_OBJ) {
//進行此項操作,將有這個函數事件被響應
}
},
"separator"//這個是在兩個操作之間畫一條分隔線
,
{
id : "edit",
label : "編輯目錄信息",
visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); },
icon : "<%=request.getContextPath() %>/image/reg2.gif",
action : function (NODE, TREE_OBJ) {
openWindow('myurl','','',function(){treeRefresh($(NODE).attr("id"));});
}
},
"separator"
,
{
id : "privilege",
label : "設置目錄許可權",
visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); },
icon : "<%=request.getContextPath() %>/css/themes/default/rename.png",
action : function (NODE, TREE_OBJ) {
openWindow('myurl','','',function(){treeRefresh($(NODE).attr("id"));});
}
},
"separator",
{
id : "delete",
label : "刪除",
visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); },
icon : "<%=request.getContextPath() %>/css/themes/default/remove.png",
action : function (NODE, TREE_OBJ) {
var tree=$.tree_reference("browser");
openWindow('myurl','','',function(){
//下邊的.parent()和.refresh()均為v0.9.8版本提供,如果你使用的是其他版本如v0.9.6等,這些將不被支持。
NODE=$(tree.parent(NODE));
if($(NODE).attr("id")==undefined){
tree.refresh();
}else{
TreeRefresh();
}
});
}
},
"separator",
{
id : "others",
label : "其他操作",
visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("creatable", NODE); },
icon : "<%=request.getContextPath() %>/css/images/cut.png",
action : function (NODE, TREE_OBJ) {
alert("暫無可提供操作。");
}
}
]
},
callback : {
onselect: function(node) {
//(a);
}
}
});
function treeRefresh(nodeid){
var rid=nodeid;
var tree=$.tree_reference("browser");
var par_node=tree.parent($("#"+rid));
tree.refresh(par_node);
}
});
E. jsTree想實現點擊父節點的文字展開, 而不是點左邊的下來按鈕, 我查了官方的API, 沒找的合適
剛好來我也碰到這源個問題。bind("select_node.jstree", function (event, data) { //myThis.id 是jstree的Id,還有你必須設置每個節點的id
$('#' + myThis.id).jstree("toggle_node", "#"+data.rslt.obj.attr("id"));
})
F. 如何獲得所有選中的節點jstree
var ref = $('#jstree').jstree(true);//獲得整個樹
sel = ref.get_selected(); //獲得所有選中節點,返回值為數組專
或者
sel = ref.get_top_selected(); //獲得所有選中的頂層屬節點,返回值為數組
G. jquery jstree的 refresh函數怎麼用
var tree = jQuery.jstree.reference("#jstree");
tree.refresh();
請參考這個國外的網址: http://stackoverflow.com/questions/3682045/how-can-i-refresh-the-contents-of-a-jstree。
我是用ajax載入的jstree,在一個button的onclick中調用了上面兩段代碼,成功刷新了jstree!
H. jstree 樹結構有兩種分類,怎麼只選擇其中一棵樹
思路就是:找出父節點的所有子節點的checked的屬性設置成與父節點一致即可
我是利用jquery實現,看看是否符合你的要求
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#tree").treeview();
$("input[name='ids']").click(function(){
var checkedValue = this.checked;
$(this).parent("li").find("input[name='ids']").attr("checked",checkedValue);
});
})
</script>
<ul id='tree'>
<li>
<input type='checkbox' name='ids' id="test"/>
<span class='folder'>test1</span>
<ul>
<li>
<input type='checkbox' name='ids' />
<span class='folder'>test11</span>
</li>
</ul>
<ul>
<li>
<input type='checkbox' name='ids' />
<span class='folder'>test12</span>
<ul>
<li>
<input type='checkbox' name='ids' />
<span class='folder'>test121</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>