PDA

View Full Version : Ext.getStore('myStoreId').load(); loads via proxy but all records are undefined?!



silent
21 Oct 2011, 3:52 AM
Hey,

I'm loading via proxy my data from a remote service. All fine, the data returns, the store gets filled with all the records but all records are undefined, why?

I've created a Store in my init function with:

Ext.create('MyProject.store.MyStore', {
storeId: 'myStoreId'
});

at one user interaction I need to load all the data into my store to fill my Ext.grid.Panel - I just use this:

Ext.getStore('myStoreId').load()

The server gets all data in JSON format and my stores reader adds all data to the store, the grid gets filled, but all fields are empty... Even when I try to echo the data to the firebug console.log() all records are 'undefined'.

What's going on?

Thanks in advance!

ferengidedalo
21 Oct 2011, 3:55 AM
put the code where you use console.log you should check the contents of the store using a callback event of the load method. load is async so you should wait for the load to finish to check the contents...

silent
21 Oct 2011, 4:29 AM
Okay, on the callback function I get phantom records and all of my records are existent but all attributes are undefined. The success is set to true and so Ext must be able to parse the JSON, what happened? ~o)

ferengidedalo
21 Oct 2011, 6:39 AM
please put the code of your model, and the response from the server... the json that the browser receives...

silent
21 Oct 2011, 7:01 AM
Model:


Ext.define('MyProject.model.MyData', {
extend: 'Ext.data.Model',

fields: [
{ type: Ext.data.Types.STRING, name: 'username' },
{ type: Ext.data.Types.STRING, name: 'ts_login' },
{ type: Ext.data.Types.STRING, name: 'ts_logout' },
{ type: Ext.data.Types.STRING, name: 'language' }
]
});

Store:


Ext.define('MyProject.store.MyDatas', {
extend: 'Ext.data.Store',
model: 'MyProject.model.MyData',

autoLoad: false,
pageSize: 5,

proxy: {
type: 'ajax',
url: '/patth/to/my/handler.ashx/loadMyDatas', // via GET
reader: {
type: 'json',
root: 'result'
},
// this is just a static "query"
extraParams: {
"username": "ALLUSERS",
"loginstart": "2011-10-03 00:00:00.000 +02:00",
"loginend": "2011-10-21 23:59:59.999 +02:00",
"language": "ALL"
},
noCache: false,

limitParam: undefined,
pageParam: undefined,
startParam: undefined
},

listeners: {
'load': function(scope, records, successful, operation, eOpts) {
console.log('username: ' + records.username + '\n');
console.log('login: ' + records.ts_login + '\n');
console.log('logout: ' + records.ts_logout + '\n');
console.log('language: ' + records.language + '\n');
}
}
});

Code in App:


initStoreLoginDatas: function() {
Ext.create('MyProject.store.MyDatas', {
storeId: 'myDatas'
});
}

[...]

Ext.getStore('myDatas').load();


GET Request:




language
ALL


loginend
2011-10-21 23:59:59.999 +02:00


loginstart
2011-10-03 00:00:00.000 +02:00


username
ALLUSERS






JSON Response:


{"id":-1,"result":["{ \"username\" : \"pahi\", \"ts_login\" : \"2011-10-14 10:15:45.000\", \"ts_logout\" : \"2011-10-21 16:31:38.000\", \"language\" : \"DE\" }","{ \"username\" : \"rawe\", \"ts_login\" : \"2011-10-14 14:02:23.000\", \"ts_logout\" : \"\", \"language\" : \"DE\" }","{ \"username\" : \"peha\", \"ts_login\" : \"2011-10-14 14:02:33.000\", \"ts_logout\" : \"2011-10-14 18:10:55.000\", \"language\" : \"FR\" }","{ \"username\" : \"hrae\", \"ts_login\" : \"2011-10-14 14:02:40.000\", \"ts_logout\" : \"\", \"language\" : \"CH\" }","{ \"username\" : \"phri\", \"ts_login\" : \"2011-10-14 14:02:47.000\", \"ts_logout\" : \"\", \"language\" : \"FR\" }","{ \"username\" : \"ajge\", \"ts_login\" : \"2011-10-14 14:02:57.000\", \"ts_logout\" : \"\", \"language\" : \"DE\" }"]}

ferengidedalo
21 Oct 2011, 7:11 AM
hi! records is an array of records.. so you cannot:

console.log('username: ' + records.username + '\n');

you should :


console.log('username: ' + records[0].get('username') + '\n');

it always work for me to make console.log(arguments) and explore from there what I receive...

skirtle
21 Oct 2011, 1:00 PM
Your JSON appears to be incorrect. results is an array containing one big string, it shouldn't be. You've got escaping issues on your server.

silent
24 Oct 2011, 11:05 PM
Your JSON appears to be incorrect. results is an array containing one big string, it shouldn't be. You've got escaping issues on your server.

Thank you, that was the problem I haven't seen. I fixed it, now it works! great! Thanks again! ;)