Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要ExtJS3.4的树过滤器的简单工作示例_Javascript_Extjs_Tree_Extjs3 - Fatal编程技术网

Javascript 需要ExtJS3.4的树过滤器的简单工作示例

Javascript 需要ExtJS3.4的树过滤器的简单工作示例,javascript,extjs,tree,extjs3,Javascript,Extjs,Tree,Extjs3,如何将树过滤器应用于树面板? 我知道这似乎是一个简单的问题,但我对处理一些复杂代码的extjs还不熟悉(从我的角度来看)。我不知道如何将树过滤器应用于树面板。我找到了关于树过滤器的文档,但我不知道如何在树面板上使用它 以下是我的树面板的代码: { xtype: 'treepanel', loader: new Ext.tree.TreeLoader(), itemId:'TreePanelThi

如何将树过滤器应用于树面板?

我知道这似乎是一个简单的问题,但我对处理一些复杂代码的extjs还不熟悉(从我的角度来看)。我不知道如何将树过滤器应用于树面板。我找到了关于树过滤器的文档,但我不知道如何在树面板上使用它

以下是我的树面板的代码:

{                                       
    xtype: 'treepanel',
    loader: new Ext.tree.TreeLoader(),
    itemId:'TreePanelThisUserCanSee',
    rootVisible: false,
    border: true,
    autoScroll: true,
    hideCollapseTool: true,
    animate: false,
    getSelectedArray: function () {
        var selNodes = this.getChecked();
        var msg = '';
        var assignArray = new Array();
        Ext.each(selNodes, function(node) {
            if(!node.disabled) {
                if(msg.length > 0){
                    msg += ', ';
                }
                msg += node.id;
                assignArray[assignArray.length] = node.id;
            }
        });
        return assignArray;
    },
    root: new Ext.tree.AsyncTreeNode({
        text: 'Locations',
        draggable: false,
        id: 'root*node',
        leaf: false,
        expanded: true,
        expandable: false,
        children: [] // must have this to programatically add
    }),
    listeners: {
        'checkchange': function(node, checked) { 
        if(checked) {
            if( node.hasChildNodes() ) {
                node.expand(false, false);
                node.eachChild(function () {
                    this.ui.toggleCheck(true);
                    if(this.hasChildNodes()) {
                        this.eachChild(function () {
                            this.ui.toggleCheck(true);
                        });
                    }
                });
            }
        } else {
            node.eachChild(function () {
            this.ui.toggleCheck(false);
            if(this.hasChildNodes()) {
                this.eachChild(function () {
                    this.ui.toggleCheck(false); 
                });
            }                                                       
        });
    }
}
}
}
使用筛选器读取和检查远程树

您还可以检查以下代码:

var config = {
        readOnly: false,
        isExpand: false,
        mode: 'local',
        treeFilter:  new Ext.tree.TreeFilter(this.getTree(), {
            autoClear: true,
            filterBy : function(fn, scope, startNode){
                startNode = startNode || this.tree.root;
                if(this.autoClear){
                    this.clear();
                }
                var found = {};
                var af = this.filtered, rv = this.reverse;
                var f = function(n){
                    if(n == startNode){
                        return true;
                    }
                    if(af[n.id]){
                        return false;
                    }
                    var m = fn.call(scope || n, n);
                    if(!m || rv){
                        af[n.id] = n;
                        //                        n.ui.hide();
                        //                        return false;
                        return true;
                    }

                    found[n.id] = n;
                    return true;
                };

                startNode.cascade(f);

                for(var idf in found){
                    if(typeof idf != "function"){
                        var curFoundItem = found[idf];
                        var p = curFoundItem.parentNode;
                        while(p){
                            delete af[p.id];
                            p = p.parentNode;
                        }
                    }
                }

                for(var id in af){
                    if(typeof id != "function"){
                        var n = af[id];
                        n.ui.hide();
                    }
                }

                //startNode.cascade(f2);

                if(this.remove){
                    for(var id in af){
                        if(typeof id != "function"){
                            var n = af[id];
                            if(n && n.parentNode){
                                n.parentNode.removeChild(n);
                            }
                        }
                    }
                }
            }
        }),

        listeners: {
            scope: this,
            beforequery: function(){
              return false;
            },
            keyup: {
                fn: function(field, key){
                    if(!this.isExpand)
                        this.expand();
                    var value = field.getRawValue();
                    if(Ext.isEmpty(value) && !Ext.isEmpty(field.treeFilter)){
                        field.treeFilter.clear();
                        return;
                    }
                    var re = new RegExp('' + value + '', 'i');
                    var tree = field.getTree();
                    tree.expandAll();
                    field.treeFilter.filter(re);
                },
                buffer: 250
            }
        }
    }
我希望这对你有帮助