jstree碎知识

<link rel="stylesheet" type="text/css" href="#{config.context}/assets/global/plugins/jstree/dist/themes/default/style.min.css"/>

<script src="#{config.context}/assets/global/plugins/jstree/dist/jstree.js"></script>

	<div class="portlet-body form">
			<form id="saleForm" class="form-horizontal">
				<input type="hidden" id="checkboxSaleIds" name="checkboxSaleIds" />
				<div class="modal-body">
					<div class="row">
						<div class="form-group">
							<input type="hidden" id="selectedSalesMan" name="selectedSalesMan" />
						</div>
						<div class="scroller" style="height:400px;">
							<div id="jstree" class="tree-demo"></div>
						</div>
			
					</div>
				</div>
				<div class="modal-footer">
					<div class="col-md-offset-4 col-md-3">
						<button type="submit" class="btn blue " >
							<i class="fa fa-check"></i>  确定
						</button> 
						<button type="button" data-dismiss="modal" class="btn btn-default" >
							<i class="fa fa-times"></i>  关闭
						</button>
					</div>
				</div>
			</form>
		</div>

//选中指定的节点(3中方式)
// 3 ways of doing the same thing
$('#jstree').jstree(true)
  .select_node('mn1');//mn1为节点ID
$('#jstree')
  .jstree('select_node', 'mn2');//mn2为节点ID
$.jstree.reference('#jstree')
  .select_node('mn3');//mn3为节点ID

//获取值: 
function getSelectedValue() {  
    var nodes = $.jstree.reference($("#JsTree")).get_selected();  
    $.each(nodes, function(i, n) {  
          
    });  
}  
function getMenuIds(){   
    
 //取得所有选中的节点,返回节点对象的集合
      var ids="";
      var nodes=$("#JsTree").jstree("get_checked")搜索; //使用get_checked方法 
      $.each(nodes, function(i, n) { 
      ids += $(n).attr("id")+",";
      }); 
      alert(ids);

}
//jsTree想实现点击父节点的文字展开, 而不是点左边的下来按钮
//答案1
刚好我也碰到这个问题。bind("select_node.jstree", function (event, data) {   //myThis.id 是jstree的Id,还有你必须设置每个节点的id			 $('#' + myThis.id).jstree("toggle_node", "#"+data.rslt.obj.attr("id"));       })


正好我用到了$("#jstree的ID").jstree("toggle_node", $(this).parent());

$.jstree.reference("#authoriytysTree").is_parent(nodeId);//判断是否为父节点
$.jstree.reference("#authoriytysTree").get_node(nodeId);//获取节点对象
//取半选节点ID
$("#authoriytysTree li").has("i[class*='jstree-undetermined']").each(function(){
            		codeIds+=","+$(this).attr("id");
            		console.log(codeIds);
            	});

//取消全部选择项
$("#authoriytysTree").jstree("deselect_all");

你可能感兴趣的:(jstree)