Extjs 解析TreeStore数据甚至是折叠的节点

Extjs 解析TreeStore数据甚至是折叠的节点,extjs,Extjs,我有一个树面板和它的树洞和模型。 我已经使用node.appendChild newNode将节点添加到树中;不使用商店 现在我需要解析所有节点。我试过这个: dataPanelsStore.each(function(record,id){ console.log(record); }); 但请注意,这将只解析扩展的节点,即可见节点 如何解析所有内容?解析节点意味着,无论是否展开,都要获取每个节点的数据 如果是,请查看此方法。至少从5.1.2开始,您可以将includedOption

我有一个树面板和它的树洞和模型。 我已经使用node.appendChild newNode将节点添加到树中;不使用商店

现在我需要解析所有节点。我试过这个:

dataPanelsStore.each(function(record,id){
    console.log(record);
});
但请注意,这将只解析扩展的节点,即可见节点


如何解析所有内容?

解析节点意味着,无论是否展开,都要获取每个节点的数据


如果是,请查看此方法。

至少从5.1.2开始,您可以将includedOptions对象传递给方法:

我尝试在fiddle中使用5.1.1.451-Gray,它仍然只显示扩展的节点。不过,在将TreeStore.js代码复制到fiddle之后,它工作得很好

这就是你能做的:

Ext.getStore('treestore').each(function(record,id){
    if(record.id !== 'root')
    console.log(record.data.name);
},this,{collapsed:true});
您还可以在第三个参数对象中传递filtered:true以包括过滤出的节点

下面是一个完整的示例,您可以复制到小提琴并运行:


    Ext.application({
    name : 'Fiddle',
    launch : function() {
       Ext.define('myApp.Territory', {
    extend: 'Ext.data.TreeModel',
    fields: [{
        name: 'text',
        mapping: 'name'
    }]
});
Ext.define('myApp.Country', {
    extend: 'Ext.data.TreeModel',
    fields: [{
        name: 'text',
        mapping: 'name'
    }]
});
Ext.define('myApp.City', {
    extend: 'Ext.data.TreeModel',
    fields: [{
        name: 'text',
        mapping: 'name'
    }]
});
var tp = Ext.create('Ext.tree.Panel', {
    renderTo: document.body,
    height: 200,
    width: 400,
    title: 'Sales Areas - using typeProperty',
    rootVisible: false,
    store: {
        // Child types use namespace of store's model by default
        storeId:'treestore',
        model: 'myApp.Territory',
        proxy: {
            type: 'memory',
            reader: {
                typeProperty: 'mtype'
            }
        },
        root: {
            children: [{
                name: 'Europe, ME, Africa',
                mtype: 'Territory',
                children: [{
                    name: 'UK of GB & NI',
                    mtype: 'Country',
                    children: [{
                        name: 'London',
                        mtype: 'City',
                        leaf: true
                    }]
                }]
            }, {
                name: 'North America',
                mtype: 'Territory',
                children: [{
                    name: 'USA',
                    mtype: 'Country',
                    children: [{
                        name: 'Redwood City',
                        mtype: 'City',
                        leaf: true
                    }]
                }]
            }]
        }
    }
});
Ext.getStore('treestore').each(function(record,id){
    if(record.id !== 'root')
    console.log(record.data.name);
},this,{collapsed:true});
    }
});


是的,你说得对。我需要做一些处理,需要得到每个节点的数据。我认为,让我们说正确的,方法是搜索存储,而不是树节点本身,但我会尝试一下。如果绑定到树的存储被过滤,那么过滤后的记录将只显示在树中。和Ext.store.each方法将只检查已过滤的记录。存储未被过滤。似乎它只能看到展开的节点。。。。如果我展开all,那么all可以正常工作,但我无法展开所有树,因为用户仍在使用它。我可以看到,当节点展开时,树存储本身正在加载数据。i、 e.除非通过存储扩展节点/记录,否则该节点/记录不可用。您可以检查getCount和getTotalCount是否返回相同的计数。通过代码或在树中单击展开其父节点时,该节点在存储中可用。以前没有。你能解释一下折叠的:true参数吗?在第二段代码中,我不想扩展任何内容。不能弄乱树。正如文档所解释的,通过在迭代中添加{collapsed:true},它也将处理折叠节点的子节点。您不需要展开任何节点,我只是向您展示了,通过删除展开的行来更新fiddle。