有没有办法只显示extjs树中的父节点 [英] Is there a way to only show parent nodes in a extjs tree

查看:80
本文介绍了有没有办法只显示extjs树中的父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在extjs中显示树的父节点.在我的数据存储区中,也有叶节点.

I want to show only parent nodes of a tree in extjs. In my datastore there are leaf nodes as well.

输出应类似于-


Folder 1
   Folder 1.1
Folder 2
Folder 3

推荐答案

创建一个仅获取父节点的过滤器对象,并将其添加到商店配置中:

Create a filter object that gets only parent nodes and add it to the store config:

例如仅针对父节点进行过滤:

E.g. filter for parent nodes only:

var nodeFilter = new Ext.util.Filter({
    property: 'leaf',
    value   : false
});

将其放在树存储配置中:

Putting it on the treestore config:

var yourTreeStore = Ext.create('Ext.data.TreeStore', {
    // other configs ...
    filters: [nodeFilter]
});

incutonez是正确的,我是根据API属性提交的,但没有注意到缺少的功能.它们很容易覆盖,但是可以为树存储应用过滤.这在4.1b2中对我有用:

incutonez is right, I submitted according to the API properties but did not notice the missing functions. They are easy enough to override though to apply filtering for a treestore though. This is working for me in 4.1b2:

Ext.override(Ext.data.TreeStore, {

    hasFilter: false,

    filter: function(filters, value) {

        if (Ext.isString(filters)) {
            filters = {
                property: filters,
                value: value
            };
        }

        var me = this,
            decoded = me.decodeFilters(filters),
            i = 0,
            length = decoded.length;

        for (; i < length; i++) {
            me.filters.replace(decoded[i]);
        }

        Ext.Array.each(me.filters.items, function(filter) {
            Ext.Object.each(me.tree.nodeHash, function(key, node) {
                if (filter.filterFn) {
                    if (!filter.filterFn(node)) node.remove();
                } else {
                    if (node.data[filter.property] != filter.value) node.remove();
                }
            });
        });
        me.hasFilter = true;

    },

    clearFilter: function() {
        var me = this;
        me.filters.clear();
        me.hasFilter = false;
        me.load();
    },

    isFiltered: function() {
        return this.hasFilter;
    }

});

使用此代码,您可以按照

With this overrride in your code, you could create a "leaf only" filter as a function or a property/value pair as per the Ext.util.Filter API:

// leaf only filter as a property/value pair
var nodeFilter = new Ext.util.Filter({
    property: 'leaf',
    value   : false
});

// leaf only filter as a function
var nodeFilter = Ext.create('Ext.util.Filter', {
  filterFn: function(item) {
    return !item.data.leaf;
  }
});

然后,只要取出叶子节点,就可以调用filter函数:

You could then just call the filter function whenever to take out the leaf nodes:

myTreeStore.filter(nodeFilter);

这篇关于有没有办法只显示extjs树中的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆