Ext Tree 过滤

subjectTree = new Ext.tree.TreePanel({
renderTo: subComboxTreeID,
loader: new Ext.tree.TreeLoader({dataUrl:"TBM/getSubjectByRespCenterNode.action",baseAttrs:{uiProvider:Ext.tree.TreeCheckNodeUI}}),
border: false,
rootVisible:true,
    autoScroll:true,
    checkModel: 'cascade',   //对树的级联多选 
        onlyLeafCheckable: false,//对树所有结点都可选 
root:new Ext.tree.TreeNode({text: '请选择',id:'0'}),
listeners :{"click":
function(node,e){
                if(node.id == 0){
                return false;
                }
               var temp_Record1 = Ext.data.Record.create([
{name:"id"  ,type:'string'}
   ,{name:"name",type:'string'}
]);
                var tmprd1 = new temp_Record1({
id:node.attributes.id,
name:node.attributes.text
});
var_subjectds.insert(0,tmprd1);
                rdd.set("subjectCode",node.id);
                subCom.setValue(node.attributes.id);
                Ext.get(subCom.getId()).dom.value = node.attributes.text;
                subCom.setRawValue(node.attributes.text);
subCom.collapse();
rdd.commit();
}
},
tbar:[new Ext.form.TextField({ width: 200,
    emptyText:'请输入过滤条件...',
    listeners:{
     render: function(f){
      f.el.on('keydown', filterBy, f, {buffer: 350});
     }
    }
})]

});
var hiddenPkgs = [];
function filterBy(e){
for(var i=0;i<hiddenPkgs.length;i++){
hiddenPkgs[i].ui.show();
}
var matched = [];
var text = e.target.value;
                    this.treeFilter = new Ext.tree.TreeFilter(subjectTree, {  
                    clearBlank: true,  
                    autoClear: true 
                }); 
                    //如果输入的数据不存在,就执行clear()  
                    if(!text){  
                        return;  
                    }  
                    subjectTree.expandAll();  
                    //根据输入制作一个正则表达式,'i'代表不区分大小写  
                    var re = new RegExp(Ext.escapeRe(text), 'i');  
                    //找出所有匹配的结点  
                    subjectTree.root.cascade(function(n) {  
                        if(re.test(n.attributes.text)){  
                            matched.push(n);  
                        }  
                    },this);  
                    //从每个叶子结点向根方向处理,处理所有结点的枝叶,  
                    //如果该枝叶包含匹配的结点,则保留,否则裁剪掉(隐藏)   
                    subjectTree.root.cascade(function(n) {
                        //if(n.isLeaf()){ 
                            //处理每一条子结点路径  
                            n.bubble(function(nbb){  
                                //从叶子到根,逐个剪掉  
                                var contain = false;  
                                for ( var mted = 0; mted < matched.length; mted++) {
                                    if(nbb.contains(matched[mted]) || nbb == matched[mted] ){  
                                        //包含匹配的结点  
                                        contain = true;  
                                        break;  
                                    }  
                                }  
                                //把不包含匹配结点的结点隐藏  
                                if(!contain){  
                                    nbb.ui.hide();
                                    hiddenPkgs.push(nbb);
                                    this.treeFilter.filtered[nbb.id]=nbb;
                                }  
                            },this); 
                       // }  
                     },this);
}

你可能感兴趣的:(UI,正则表达式,ext,F#)