1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    1
    Vote Rating
    0
    talvola is on a distinguished road

      0  

    Default Simple question on getting JSON data through REST using Ext.data.ArrayStore

    Simple question on getting JSON data through REST using Ext.data.ArrayStore


    newbie here - be warned.

    I took the array-grid.html/array-grid.js example from http://extjstutorial.info/extjs-4-tu...ing-extjs-4/38

    I then put the same data into a MongoDB database, using mongodb-rest for access, and a URL like this:

    http://genlinux.foo.com:3000/testing/sample

    returns:

    [{"_id":"4ffcfaf0f2c5dcf7569e4e3a","name":"Monkey D Luffy","position":"Captain","ambition":"I will become the pirate king"},{"_id":"4ffcfaf0f2c5dcf7569e4e3b","name":"Roronoa Zoro","position":"Swordman","ambition":"Become the greatest swordman"},{"_id":"4ffcfaf0f2c5dcf7569e4e3c","name":"Sanji","position":"Cook","ambition":"Find all blue"},{"_id":"4ffcfaf0f2c5dcf7569e4e3d","name":"Usopp","position":"Sniper","ambition":"Become the greatest warrior"},{"_id":"4ffcfaf0f2c5dcf7569e4e3e","name":"Nami","position":"Navigator","ambition":"Draw map of the world"}]

    so, if I modify the sample code to look like:

    var store = Ext.create('Ext.data.ArrayStore', {
    fields: [
    '_id',
    'name',
    'position',
    'ambition'
    ],
    // data: sampleData
    url: 'http://genlinux.foo.com:3000/testing/sample',
    });

    then add a:

    store.load();

    should that give the equivalent output? It basically gives an empty grid. Not sure where to start debugging - whether it's in the code, whether the URL get doesn't work, etc.

    again, sorry for the probably obvious problems - just trying to get a feeling of whether this seems like a framework to give some programmer newcomers access to our MongoDB store or not.

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,049
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Two things:

    1) Verify the request works by looking at the network traffic in the chrome dev tools or firebug. Do you see the appropriate data coming back?

    2) ArrayStore is not what you want. From the docs:

    An ArrayStore will be automatically configured with a Ext.data.reader.Array.
    If you look at that page, http://docs.sencha.com/ext-js/4-1/#!...a.reader.Array, you'll see the data isn't in the correct format.

    Instead, you would use: http://docs.sencha.com/ext-js/4-1/#!...data.JsonStore
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Thread Participants: 1