0
votes

I have a TreePanel and its TreeStore and Model. I've added nodes to the Tree by using node.appendChild( newNode ); not using the store.

Now I need to parse all nodes. I've tried this:

dataPanelsStore.each(function(record,id){
    console.log(record);
});

but noticed this will parse only expanded nodes (the visible ones).

how can I parse everything?

2

2 Answers

1
votes

Atleast from 5.1.2 you can pass includedOptions object to treestore#each method:

I tried using 5.1.1.451-Gray in fiddle , it still displayed only expanded nodes. It worked fine though after copying TreeStore.js code to fiddle.

So this is what you can do:

Ext.getStore('treestore').each(function(record,id){
    if(record.id !== 'root')
    console.log(record.data.name);
},this,{collapsed:true});

You can also pass filtered:true in third parameter object to include filtered out nodes.

Here is a full example you can copy to fiddle and run:


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

0
votes

Parsing node means, to get each node data irrespective of expanded or not?

If so, please look into this method cascade method.