PDA

View Full Version : Ext.data.reader.Json totalProperty with dot "."



stevo.zilik
7 Mar 2013, 1:54 AM
Hi

I have an usual JSON comming back from server that looks like this:


{
"values": [...],
"data.length": 100
}

where "data.length" is my totalProperty (number of total records in the dataset, for paging). The problem is when I put "data.length" into my totalProperty, it's trying to be clever and look for a "data" object with a "length" property. Is there any way of telling it not to be clever and just take the name as I've passed it?

Thanks.
Stevo

saJoshua
7 Mar 2013, 2:27 AM
javascript uses "." (dot) notation internally, so it's not advisable to use it in strings that could get confusing in a similar way to your json being misinterpreted. You wouldn't create an object with a key of "Object", would you?

{
"Object" : {}
}

Any chance you can change the dot to a different character?

stevo.zilik
7 Mar 2013, 2:49 AM
javascript uses "." (dot) notation internally, so it's not advisable to use it in strings that could get confusing in a similar way to your json being misinterpreted. You wouldn't create an object with a key of "Object", would you?

{
"Object" : {}
}

Any chance you can change the dot to a different character?

I agree with you, but unfortunately that's not something I can change. If I could, then I would... :)

So I need a solution on js side.

skirtle
7 Mar 2013, 4:31 AM
See:

http://docs.sencha.com/ext-js/4-1/source/Json2.html#Ext-data-reader-Json-method-createAccessor

You've got a wealth of options available, such as:


totalProperty: '["data.length"]'

or:


totalProperty: function(obj) {
return obj['data.length'];
}

or useSimpleAccessors:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.reader.Json-cfg-useSimpleAccessors