jstree 相关

jstree搜索置顶方法--代码以下:

if(to) { clearTimeout(to); }
   			to = setTimeout(function () {
   				var v = $('#dict_queryinput').val();
   				var searchResult = $("#dict_treeDiv").jstree('search', v);
   				var searchResultList = $(searchResult).find('.jstree-search');
   				var searchResultListLen = searchResultList.length;
   				if(searchResultListLen > 0){
   					$(searchResultList[0]).focus();
   				}else {
   					$(searchResult).find('.jstree-search').focus();
   				};
   			}, 250);
复制代码

查询 筛选 上下选中

树节点采用click 触发,是为了触发响应的表格详情,若是不须要触发详情,可使用focus

$('#dict_queryinput').keyup(function () {
   			if(to) { clearTimeout(to); }
   			to = setTimeout(function () {
   				var v = $('#dict_queryinput').val();
   				searchResult = $("#dict_treeDiv").jstree('search', v);
   				searchResultList = $(searchResult).find('.jstree-search');
   				searchResultListLen = searchResultList.length;
   				$.each($(searchResult).find('.jstree-anchor'),function(index,ele){
					$(ele).removeClass("jstree-add-focused");
				});
   				if(searchResultListLen > 1){
   					$("#dict_queryinput").attr("href","#"+$(searchResultList[0]).attr("id"))
   					$('#dict_queryinput').click();
   					$(searchResultList[0]).addClass("jstree-add-focused");
   					$(searchResultList[0]).click();
   					Dictionary.queryInputNext(searchResultList);
   					Dictionary.queryInputPrev(searchResultList);
   				}else {
   					$("#dict_queryinput").attr("href","#"+$(searchResultList[0]).attr("id"))
   					$('#dict_queryinput').click();
   					$(searchResultList[0]).addClass("jstree-add-focused");
   					$(searchResult).find('.jstree-search').click();
   				};
   			}, 250);
   		});
复制代码

点击下一个

Dictionary.queryInputNext = function(_searchResultList){
		var thisLen = _searchResultList.length;
		$("#dict_queryinput_next").off("click").on("click",function(){
			$.each(_searchResultList,function(index,ele){
					if($(ele).hasClass("jstree-add-focused")){
						if(thisLen-index > 1){
							$(ele).removeClass("jstree-add-focused");
							$("#dict_queryinput").attr("href","#"+$(_searchResultList[index+1]).attr("id"))
		   					$('#dict_queryinput').click();
							$(_searchResultList[index+1]).addClass("jstree-add-focused");
							$(_searchResultList[index+1]).click();
						}else{
							alert("这是查询到的最后一条");
							$(_searchResultList[index]).focus();
							return false;
						}
						return false;
					}
			});
		});
	}
复制代码

点击上一个

Dictionary.queryInputPrev = function(_searchResultList){
		var thisLen = _searchResultList.length;
		$("#dict_queryinput_prev").off("click").on("click",function(){
			$.each(_searchResultList,function(index,ele){
				if($(ele).hasClass("jstree-add-focused")){
					if(thisLen-index == thisLen){
						alert("这是查询到的最后一条");
						$(_searchResultList[0]).focus();
						return false;
					}else{
						$(ele).removeClass("jstree-add-focused");
						$("#dict_queryinput").attr("href","#"+$(_searchResultList[index-1]).attr("id"))
	   					$('#dict_queryinput').click();
						$(_searchResultList[index-1]).addClass("jstree-add-focused");
						$(_searchResultList[index-1]).click();
					}
					return false;
				}
		});
		});
	}
复制代码

搜索后筛选搜索结果

注意初始化时“search”和“types”的位置node

$("#jstreeId").jstree({
	    'core' : {
	        'data' : newModelTree,
	        'force_text' : true,
		    'check_callback' : true,
			'themes' : {
				"theme" : "default",
				"dots" : false
			}
	    },
		"search": {
		                "show_only_matches": true, //filtering
		                "show_only_matches_children": true

		            },
		            "types": {
		                "types": {
		                    "disabled": {
		                        "check_node": false,
		                        "uncheck_node": false
		                    }
		                }
		            },
					'plugins' : [ 'themes' , 'state','dnd','contextmenu','wholerow','search']
	    		}).on('search.jstree', function (nodes, str, res) {
	                if (str.nodes.length === 0) {
	                	$("#jstreeId").hide();
	                }
	            });
复制代码
var to = false;
var searchResult;
var searchResultList;
var searchResultListLen;
$('#queryinput').keyup(function () {
	if(to) { clearTimeout(to); }
	to = setTimeout(function () {
		$("#jstreeId").show();
		var v = $('#queryinput').val();
		 $("#jstreeId").jstree('search', v);
	}, 250);
});
复制代码
that.$ciTree.on("changed.jstree", function (e, data) {
		   			if (!data.node) {
		   				return;
		   			}
		   		    //给当前元素添加jstree-add-focused 类名,方便下面点击按钮实现
		   			if($("#"+data.node.id+">a").hasClass("jstree-search")){
		   				$(".queryinput-button").show();
		   				$("#"+data.node.id).parents(".jstree-container-ul").find(".jstree-add-focused").removeClass("jstree-add-focused");
			   			$("#"+data.node.id+">a").addClass("jstree-add-focused");
		   			}else{
		   				$(".queryinput-button").hide();
		   			}
		   			
					that.selectBmModleName = data.node.id;
					//that.reloadTable(); // 点击数操做时的code
		   	  });
复制代码
相关文章
相关标签/搜索