1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    7
    Vote Rating
    0
    testbuilder is on a distinguished road

      0  

    Question Answered: Using JsonReader with sencha

    Answered: Using JsonReader with sencha


    Hello Everyone, I am brand new with forums, with sencha and json so, may sound very naive but hopefully you guys maybe able to help me because I am pounding on this from last 48 hours. Here is what I am doing in simplest terms:

    I want to read a json string from remote URL using proxy, here is the complete code I am using in my customapp.js
    Code:
    Ext.onReady(function(){Ext.regModel('User', {
        fields: ['id', 'name', 'email']
    });
    
    
    var store = new Ext.data.Store({
        model: 'User',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url : './test.json',
            reader: {
                type: 'json'
            }
        }
    });
    console.log(store.getRange());
    });
    and this is my test.json file:
    Code:
    [{"id":1,"name":"Ed Spencer","email":"ed@sencha.com"},{"id": 2,"name":"Abe Elias","email":"abe@sencha.com"}]
    To point that, I simply wrote this string in a file, given it the extension of .json and saved it, nothing else I am doing here.

    The response in console.log I am seeing is '[]' empty array while if I dump whole of 'store', it has nothing in data.items, that means it's not reading json? Am I doing something wrong here?

  2. Hi testbuilder.
    You code is ok, however there is a little conceptual error:
    The store takes a little time to load depending on how much it have to load and, in any case, you have to wait that the AjaxRequest is completed.
    For this reason, when the

    Code:
    console.log(store.getRange());
    is executed, the store is still empty.
    If you want to see your loaded data, you can add to your store a "load" or "datachanged" listener in this way:

    Code:
    var store = new Ext.data.Store({
        model: 'User',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url : 'test.json',
            reader: {
               type: 'json'
             }
         },
         listeners: {
             load: function(){
                console.log(store.getRange());
             }
          }
    });
    Hope this helps.

  3. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,394
    Answers
    148
    Vote Rating
    22
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Hi testbuilder.
    You code is ok, however there is a little conceptual error:
    The store takes a little time to load depending on how much it have to load and, in any case, you have to wait that the AjaxRequest is completed.
    For this reason, when the

    Code:
    console.log(store.getRange());
    is executed, the store is still empty.
    If you want to see your loaded data, you can add to your store a "load" or "datachanged" listener in this way:

    Code:
    var store = new Ext.data.Store({
        model: 'User',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url : 'test.json',
            reader: {
               type: 'json'
             }
         },
         listeners: {
             load: function(){
                console.log(store.getRange());
             }
          }
    });
    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    CEO at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    http://www.tux-components.com/


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..." hd porno faketaxi