Search code examples
javascriptextjsextjs3

How to print (or alert) value from ExtJS store?


I am trying to get a value from an ExtJS store to use it in a variable. I tried to print it with console.log, following instructions from another questions answered here on StackOverflow and on Sencha forum, with no success. I am getting this error message on my first attempt:

Cannot read property 'data' of undefined

And this message on my second attempt:

myView is not defined

where "myView" is the class name of this current window.

Here is my Store code:

myStore = this.store = new Ext.data.JsonStore({
                proxy:new Ext.data.ScriptTagProxy({
                    url: "php/data.php"
                }),
            root: 'result',
            autoLoad: false,
            fields: [
                {name:'ID',type:'string',mapping:'ID'},
                {name:'NAME',type:'string',mapping:'NAME'}

            ]
        });

Here is how I am trying to get the values from store:

First attempt:

var vId = myStore.data.items[0].data.ID;
console.log(vId);

Second attempt:

store.storeDadosSol.load(function(){
                this.each(function(record){
                var vId = record.get('ID');
                // Do stuff with value
                console.log(vId);
                });
            });​

I am following these answers:

Sencha Forum

StackOverflow Question

Any ideas? I am using ExtJS version 3.2.1


Solution

  • Your myStore declaration uses

    myStore = this.store =

    When you try to access the values from the store, are you in the same scope? Is myStore a global variable?