using local storage saved value as a text in a root text

161 views Asked by At

I have a treeView in my extjs View, in which I need to give the the value of a local storage variable as the root name.The value to the local storage is fed when user logins successfully :

Ext.define('Eits.view.OrgTreeView', {
extend : 'Ext.tree.TreePanel',
requires: ['Eits.model.OrgTreeModel'],
    width : '100%',
    region : 'center',
    border : true,
    user = this.localStorageProvider.get('name'),
    store : {
        xtype : 'tree',
        fields : Eits.model.OrgTreeModel.FIELDS,
        //model: 'Eits.model.OrgTreeModel',
        autoLoad: false,
        root: {
            id: 'rootNode',
            objectId : 'rootNode',
            leaf: false,
            expanded: false,
            text : this.user, 
            iconCls : 'mts-Tree-Node',
        },
        proxy: {
            type: 'ajax',
            url: 'orgTree/getNavigationTree.action',
            actionMethods: 'POST',
            reader: {
                type: 'json',
                root: 'data'     
            }
        }
    },...

Is there a way that i could get the value from local storage and pass it as a name to tree's root.Also when I pass a static value to text field in the store's root , it does show the static value in my UI.

1

There are 1 answers

8
Greendrake On BEST ANSWER

Just move the creation of tree store inside initComponent:

Ext.define('Eits.view.OrgTreeView', {
    extend: 'Ext.tree.TreePanel',
    requires: ['Eits.model.OrgTreeModel'],
    width: '100%',
    region: 'center',
    border: true,
    initComponent: function() {
        this.store = Ext.create('Ext.data.TreeStore', {
            fields : Eits.model.OrgTreeModel.FIELDS,
            autoLoad: false,
            root: {
                id: 'rootNode',
                objectId : 'rootNode',
                leaf: false,
                expanded: false,
                text: localStorageProvider.get('name'), 
                iconCls: 'mts-Tree-Node',
            },
            proxy: {
                type: 'ajax',
                url: 'orgTree/getNavigationTree.action',
                actionMethods: 'POST',
                reader: {
                    type: 'json',
                    root: 'data'     
                }
            }
        });
        this.callParent();
    }
});