상투적인 combobox 와 combotree 모호 조회

First

/** 
 * combobox combotree    
 * combotree          (      )
 *            
 *            
 */
(function(){
 //combobox   ,        
 $.fn.combobox.defaults.editable = true; 
 $.fn.combobox.defaults.filter = function(q, row){ 
 var opts = $(this).combobox('options'); 
 return row[opts.textField].indexOf(q) >= 0; 
 }; 
 //combotree   ,        
 $.fn.combotree.defaults.editable = true;
 //     
 var leafBlockIndex=0;
 //       
 var nowLeafBlockIndex=-1;
 //combotree   
 var comboTree=null;
 //    DOM Array
 var leafBlocks=null;;
 //             DOM Array 
 function getDOMArray(data){
 comboTree = $(data).combotree('tree');
 leafBlocks=new Array();
 var leafs = comboTree.tree('getChildren');
 for (var i = 0; i < leafs.length; i++) {
  var leaf = leafs[i];
  var dis =$(leaf.target).css('display')+'';
  if('block' == dis){
  if(comboTree.tree('isLeaf',leaf.target)){
   leafBlocks.push(leaf.target);
  }
  }
 }; 
 };
 //-------------------------------------
 $.extend($.fn.combotree.defaults.keyHandler,{ 
 up:function(e){
  leafBlockIndex=nowLeafBlockIndex;
  leafBlockIndex--;
  getDOMArray(this);
  if(leafBlockIndex <0){
  leafBlockIndex=leafBlocks.length-1;
  }
  comboTree.tree('select',leafBlocks[leafBlockIndex]);
//  easyui 1.3.4     
//  comboTree.tree('scrollTo',leafBlocks[leafBlockIndex]);
  nowLeafBlockIndex=leafBlockIndex;
 },
 down:function(e){
  leafBlockIndex=nowLeafBlockIndex;
  leafBlockIndex++;
  getDOMArray(this);
  if(leafBlockIndex >= leafBlocks.length){
  leafBlockIndex=0;
  }
  comboTree.tree('select',leafBlocks[leafBlockIndex]);
//  easyui 1.3.4     
//  comboTree.tree('scrollTo',leafBlocks[leafBlockIndex]);
  nowLeafBlockIndex=leafBlockIndex;
 },
 left: function(e){
  console.log('left');
//  var val = $(this).combo('getText');
//  $(this).combo('setText',val+' ');
 },
 right: function(e){
  console.log('right');
//  var val = $(this).combo('getText');
//  console.log(val);
//  $(this).combo('setText',val+' ');
 },
 enter:function(e){
  var leaf =$(leafBlocks[nowLeafBlockIndex]);
  var value =leaf.children('span').last().text();
  $(this).combo('setText',value);
  $(this).combo('hidePanel')
 }, 
 query:function(q){
  var t = $(this).combotree('tree'); 
  var nodes = t.tree('getChildren'); 
  for(var i=0; i<nodes.length; i++){ 
  var node = nodes[i]; 
  if (node.text.indexOf(q) >= 0){ 
   $(node.target).show();
   var parent=t.tree('getParent',node.target);
   if(parent){
   $(parent.target).show();
   if(parent){
    parent=t.tree('getParent',parent.target);
    $(parent.target).show();
   }
   }
  } else { 
   $(node.target).hide(); 
  } 
  } 
  var opts = $(this).combotree('options'); 
  if (!opts.hasSetEvents){
  opts.hasSetEvents = true; 
  var onShowPanel = opts.onShowPanel; 
  opts.onShowPanel = function(){ 
   var nodes = t.tree('getChildren'); 
   for(var i=0; i<nodes.length; i++){ 
   $(nodes[i].target).show(); 
   } 
   onShowPanel.call(this); 
  }; 
  $(this).combo('options').onShowPanel = opts.onShowPanel; 
  }
 }
 });
})(jQuery);
Second

(function ($) {
 //combotree   ,        
 $.fn.combotree.defaults.editable = true;
 $.extend($.fn.combotree.defaults.keyHandler, {
 query: function (q) {
  var t = $(this).combotree('tree');
  t.tree("search", q);
 }
 });
 $.extend($.fn.tree.methods, {  /** 
  *   easyui tree      
  * @param tree easyui tree  DOM  (UL  ) jQuery    * @param searchText       
  * @param this-context easyui tree tree    */
 search: function (jqTree, searchText) {
  //easyui tree tree  。    tree.methodName(jqTree)    easyui tree    
  var tree = this;
  //         
  var nodeList = getAllNodes(jqTree, tree);
  //        ,         
  searchText = $.trim(searchText);
  if (searchText == "") {
  for (var i = 0; i < nodeList.length; i++) {
   $(".tree-node-targeted",
  nodeList[i].target).removeClass("tree-node-targeted");
   $(nodeList[i].target).show();
  }
  //        (       )  
  var selectedNode = tree.getSelected(jqTree);
  if (selectedNode) {
   tree.expandTo(jqTree, selectedNode.target);
  }
  return;
  }
  //              
  var matchedNodeList = [];
  if (nodeList && nodeList.length > 0) {
  var node = null;
  for (var i = 0; i < nodeList.length; i++) {
   node = nodeList[i];
   if (isMatch(searchText, node.text)) {
   matchedNodeList.push(node);
   }
  }
  //       
  for (var i = 0; i < nodeList.length; i++) {
   $(".tree-node-targeted", nodeList[i].target).removeClass("tree-node-targeted");
   $(nodeList[i].target).hide();
  }
  //       
  tree.collapseAll(jqTree);
  //               


  for (var i = 0; i < matchedNodeList.length; i++) {
   showMatchedNode(jqTree, tree, matchedNodeList[i]);
  }
  }
 },
 /** 
 *         (                 ) 
 * @param node easyui tree    
 */
 showChildren: function (jqTree, node) {
  //easyui tree tree  。    tree.methodName(jqTree)    easyui tree    
  var tree = this;
  //      
  if (!tree.isLeaf(jqTree, node.target)) {
  var children = tree.getChildren(jqTree, node.target);
  if (children && children.length > 0) {
   for (var i = 0; i < children.length; i++) {
   if ($(children[i].target).is(":hidden")) {
    $(children[i].target).show();
   }
   }
  }
  }
 },
 /** 
 *               ,      (         ,         ) 
 * @param param { 
 * treeContainer: easyui tree   (          )。   null,  easyui tree  UL      。 
 * argetNode:       easyui tree  。  targetNode  ,              ,         ,      * }  */
 scrollTo: function (jqTree, param) {
  //easyui tree tree  。    tree.methodName(jqTree)    easyui tree    
  var tree = this;
  //  node  ,        node 
  var targetNode = param && param.targetNode ? param.targetNode : tree.getSelected(jqTree);
  if (targetNode != null) {
  //              var root = tree.getRoot(jqTree); 
  var $targetNode = $(targetNode.target);
  var Container = param && param.treeContainer ? param.treeContainer : jqTree.parent();
  var containerH = container.height();
  var nodeOffsetHeight = $targetNode.offset().top - container.offset().top;
  if (nodeOffsetHeight > (containerH - 30)) {
   var scrollHeight = container.scrollTop() + nodeOffsetHeight - containerH + 30;
   container.scrollTop(scrollHeight);
  }
  }
 }
 });
 /** 
  *           */
 function showMatchedNode(jqTree, tree, node) {
 //        
 $(node.target).show();
 $(".tree-title", node.target).addClass("tree-node-targeted");
 var pNode = node;
 while ((pNode = tree.getParent(jqTree, pNode.target))) {
  $(pNode.target).show();
 }
 //       
 tree.expandTo(jqTree, node.target);
 //        ,             
 if (!tree.isLeaf(jqTree, node.target)) {
  tree.collapse(jqTree, node.target);
 }
 }
 /** 
 *   searchText   targetText   
 * @param searchText       * @param targetText      
 * @return true-            ;   false. 
 */
 function isMatch(searchText, targetText) {
 return $.trim(targetText) != "" && targetText.indexOf(searchText) != -1;
 }
 /** 
 *   easyui tree   node   */
 function getAllNodes(jqTree, tree) {
 var allNodeList = jqTree.data("allNodeList");
 if (!allNodeList) {
  var roots = tree.getRoots(jqTree);
  allNodeList = getChildNodeList(jqTree, tree, roots);
  jqTree.data("allNodeList", allNodeList);
 }
 return allNodeList;
 }
 /** 
 *     easyui tree          */
 function getChildNodeList(jqTree, tree, nodes) {
 var childNodeList = [];
 if (nodes && nodes.length > 0) {
  var node = null;
  for (var i = 0; i < nodes.length; i++) {
  node = nodes[i];
  childNodeList.push(node);
  if (!tree.isLeaf(jqTree, node.target)) {
   var children = tree.getChildren(jqTree, node.target);
   childNodeList = childNodeList.concat(getChildNodeList(jqTree, tree, children));
  }
  }
 }
 return childNodeList;
 }
})(jQuery);
이상 의 이 상투적인 콤 보 박스 와 콤 보 트 리 의 모호 한 조 회 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 에 게 참고 가 되 고 여러분 들 이 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기