PDA

View Full Version : Sending extra info to JsonStore



jazzapis
5 Jan 2013, 2:16 AM
It is possible to send some extra data to jsonstore?

Bassicaly json data looks like this:
{"success":true,"totalCount":25,"items":[{...}]}

I need send something more, eg:
{"success":true,"totalCount":25,"title":"Documents","message":"bla bla bla","items":[{...}]}

It is possible to read this extra fields in Ext.data.JsonStore?

mitchellsimoens
7 Jan 2013, 9:39 AM
A reader has a createAccessor method that you pass in the property you want to use. This method will return a method that you pass in the raw data from the response and when you execute that method it will return the value.


this.createAccessor('title')(rawData) === 'Documents'

I usually cache the function the createAccessor on the store so that I'm not creating the function over and over

jazzapis
7 Jan 2013, 11:28 AM
I'm not sure I understand


I try something like this:


var store = new Ext.data, JsonStore ({
id: 'ID',
totalProperty: 'totalCount'
root: 'items',
url: 'getData.php'
fields: [...]
listeners: {
load: function (store, records, opts) {
var fnTitle = store.reader.createAccessor('title');


And then what?
I have some function fnTitle()
But any call of this method fires exception

How to retrive value of "title" item from JSON structure?

jazzapis
18 Jan 2013, 9:13 AM
I found solution

Any element of JSON structure can be read by:
store.reader.jsonData.<element>

eg:
{"success":true,"totalCount":25,"title":"Documents","message":"bla bla bla","items":[{...}]}

can be read by:
store.reader.jsonData.title