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);
新闻热点
疑难解答
图片精选