-
10 Jul 2012 8:34 PM #1
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.
-
10 Jul 2012 8:55 PM #2
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:
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.An ArrayStore will be automatically configured with a Ext.data.reader.Array.
Instead, you would use: http://docs.sencha.com/ext-js/4-1/#!...data.JsonStoreEvan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!


Reply With Quote