1. 程式人生 > >combotree可編輯,自定義模糊查詢

combotree可編輯,自定義模糊查詢

combotree可編輯

$.fn.combotree.defaults.editable = true;  //單獨書寫

 

editable: true,   //在combotree中書寫如:

$('#orgName').combotree({  editable: true,})

 

自定義模糊查詢

        $.extend($.fn.combotree.defaults.keyHandler,{  

            up:function(){  

                console.log('up');  

            },  

            down:function(){  

                console.log('down');  

            },  

            enter:function(){  

                console.log('enter');  

            },  

            query:function(q){ 

                var reg=/^[\u4E00-\u9FA5]+$/;  

                if(reg.test(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();  

                        } else { 

                            var ns=t.tree('getParent',node.target);

                            if (ns != null) {

                                if (ns.text.indexOf(q) >= 0) {

                                    $(node.target).show();

                                } else {

                                    var ts = t.tree('getParent', ns.target)

                                    if (ts != null && ts.text.indexOf(q) >= 0) {

                                        $(node.target).show();

                                    } else {

                                        $(node.target).hide();

                                    }

                                }

                            } 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;  

                    }    

                }else if(q==""){

                     var t = $(this).combotree('tree');  

                        var nodes = t.tree('getChildren');  

                        for(var i=0; i<nodes.length; i++){  

                            var node = nodes[i];  

                             $(node.target).show();  

                        }  

                }

            }  

        });