PDA

View Full Version : Store load success with no data



r4nd7263
29 Jul 2011, 7:05 AM
I am trying to load some application setup data before I show the viewport.



this.store = new Ext.data.Store({
model : "MyApp",
proxy : {
type : 'scripttag',
url : "http://www.mydomain.com/rest/app/10000/setup",
reader : {
type : 'json'
}
}
});
this.store.load({
scope : this,
callback : function(records, operation, success) {
// console.log("loaded");
console.log(records);
console.log(operation);
console.log(success);
console.log(this.store);
this.viewport = new this.view.Viewport();
}
});
Looking at console in Chrome, records is [], this.store.data.items is Array[0], but success is true.
There are no other errors and viewport renders fine except missing data.

I am wondering where and how to retrieve my data? Or if something went wrong, how do I go about debugging this?

jjerome
29 Jul 2011, 7:07 AM
Can you look at the Network tab in the debugger to see what data you are getting back?

r4nd7263
29 Jul 2011, 7:45 AM
Server Response: 200 OK
Content-Length: 841
Content-Type: text/javascript
Content: stcCallback1001({"id":1000,"appName":"Test App" ...})

... means I stripped out the rest. Though I am confident the syntax is correct.

MyApp is registered like this.



Ext.regModel("MyApp", {
fields: [
{name: "id", type: "long", defaultValue: -1},
{name: "appName", type: "string", defaultValue: ""}
]
});

jjerome
29 Jul 2011, 7:58 AM
What is under the Content tab in the Network? Not the Header.

r4nd7263
29 Jul 2011, 9:49 AM
I think my problem is I am not defining reader.root, but I can't since it's not a collection. Maybe store isn't the right choice, is there an example for retrieving non-collection data?

Also according to document, exception should be thrown if root is undefined, so is this a bug?

jjerome
29 Jul 2011, 10:00 AM
Definitely use a root for the reader if you can.
http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Reader if you need a reference.

How are you setting up the data that you want to be returned? Or what should be returned?

r4nd7263
29 Jul 2011, 10:09 AM
Yep. As soon as I change to serve:

stcCallback1001([{"id":1000,"appName":"Test App" ...}])

(note the extra bracket for JSON array)

But it's not good solution since I have to change server to serve array (even if it is meant to return a single record).

I am still looking for example on loading single record.

*EDIT: The closest thing I found is http://www.sencha.com/forum/showthread.php?121668-return-json-data-where-root-is-not-an-array/page2&highlight=single+data . This is something the framework should address (or at least explain more clearly).

jjerome
29 Jul 2011, 10:44 AM
Good find r4nd7263.

I wish I would search the forum more before answering posts. It would help from building further threads on similar/same issues.

Best of luck!