PDA

View Full Version : How to test successProperty?



aorlic
4 Apr 2012, 6:00 AM
Hello all!

I use a Store to load data. I understand that proxy.reader's "successProperty" is set AFTER the response from server, representing APP-SPECIFIC response state (an not some lower-level problem, like bad-formatted Json or DB error).

This is a fragment of the Json response:
{
"status": {
"success": false,
"code": 8,
...

and this is a proxy code snippet:

proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
...

I simply cannot find WHERE should I check the successProperty field after the load()'s callback has been called?
All the "candidates" are TRUE, although it comes as FALSE from the server...

Thank you for any help!

Aleksandar.

mitchellsimoens
4 Apr 2012, 8:40 AM
Here is a test case for Ext JS 4:


Ext.define('MyModel', {
extend : 'Ext.data.Model',

fields : ['test']
});

new Ext.data.Store({
model : 'MyModel',
autoLoad : true,
proxy : {
type : 'ajax',
url : 'data/json.json',
reader : {
type : 'json',
root : 'data'
}
},
listeners : {
load : function(store, records, success) {
console.log(success);
}
}
});

With this JSON:


{
"success": false,
"data": [
{
"test": "bam!"
}
]
}

The success argument in the load listener is then false.

mitchellsimoens
4 Apr 2012, 8:40 AM
Moved to Ext JS 4 Q&A forum.

aorlic
4 Apr 2012, 11:38 AM
Thank you, I'll test it immediatelly.

BTW, I am wondering where is the successProperty now?! I don't see it in your code...

mitchellsimoens
4 Apr 2012, 11:45 AM
successProperty defaults to 'success' so for my JSON it's not needed.

aorlic
5 Apr 2012, 1:22 AM
Thank you, your example helped me solve the problem.

As my successProperty is in the 2nd level of the JSon tree, I must reference it by "status.success" unstead and it works.