1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    2
    Vote Rating
    0
    mentizm is on a distinguished road

      0  

    Question how to load data from store

    how to load data from store


    Hello im new in Extjs and also in javascript. i hope you can help me by solving this problem, maybe its easy to solve but i have no more ideas. Here are my code
    Code:
    Ext.define('User', {
            extend: 'Ext.data.Model',
            fields: [
                    {name: 'firstName', type: 'string'},
                    {name: 'lastName',  type: 'string'},
                    {name: 'age',       type: 'int'},
                    {name: 'eyeColor',  type: 'string'}
            ]
    });
    
    var store = Ext.create('Ext.data.Store',{
            model: 'User',
            proxy: {
                    type: 'ajax',
                    url : 'app/user.php',
                    reader: {
                            type: 'json',
                            model: 'User',
                            root: 'users'
                    }
            },
    });
    This is the JSON that the user.php file returns
    HTML Code:
    {"users": [{"firstName" : "peter","lastName" : "parker","age" : 23,"eyeColor" : "brown",},{"firstName":"horst","lastName" : "lattek","age" : 21,"eyeColor":"green",}] }.
    now my problem:

    i want to get the 'firstName' of the second USER and my idea to solved it is:
    var result = store.getAt(1);
    result.get('firstName');

    Firebug (i work on firefox) give the FAILURE: result.get() -> result is undefined.

    and when i use store.count() to check the input of the store it returns "0" ??? why ???
    when count is 0 i think there is a mistake in the PROXY READER and there is no mapping to the USER model ... but when i use this code:
    Code:
    store.load({
    callback: function() {
            //the user that was loaded
            var user = store.first();
            console.log("Name: " + user.get('firstName'))
        }
    });
    the console gives me "peter" ??? also i think the json was read right ... please help me!
    thank you ... mentizm!

    i hope you understand everything ... its late in germany

  2. #2
    Sencha User
    Join Date
    Feb 2008
    Posts
    29
    Vote Rating
    0
    solodesignz is on a distinguished road

      0  

    Default


    Just a quick response...

    Are you calling the getAt before the store data is loaded?

    try something like:

    Code:
    store.on('load', function () {
            console.log(store.getAt(1).get('firstName'));
        });
    Or, use the getAt function inside the load() callback

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    2
    Vote Rating
    0
    mentizm is on a distinguished road

      0  

    Question


    Hy solodesignz,

    thanks for the quick response. but its not that what i want. i try to explain with an other example:

    after i define the MODEL and the STORE and everythings works fine. that means that the store contain the right values. i checked it with youre new example code too. by the way ... it works fine .

    Code:
    store.on('load', function () {   console.log(store.getAt(0).get('firstName'));
    
    });
    
    >>> peter
    
    same with ... console.log(store.first().get('firstName'));
    but what i need is something like this:

    i create a new and empty model:
    Code:
    var user = Ext.create('User');
    and what i want is to make this:
    Code:
    user = store.getAt(0);
    
    user.get('firstName') >>> peter
    how can i solve this? i want to use the createt user everywhere in the actually xyz.js file.

    is it possible?

    thanks

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."