PDA

View Full Version : IS it possible to get some random information from json reader



bugsbunny
2 Jun 2009, 9:06 AM
Hi friends,
I am new to Extjs. I wondering if we can pass some custom property in the json reader and
be able to access it.

For eg the Json reader is something like this
var Employee = Ext.data.Record.create([
{name: 'firstname'},
{name: 'job', mapping: 'occupation'}
]);


var myReader = new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "id" //
}, Employee);


Now can I add somemore properties like say employeeGroup which will something look like


var myReader = new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "id"
employeeGroup : "empGrp"
}, Employee);
And how can I access such a property.

I was looking in the source and it seems that this class is quite specific

Please help with example ..if possible ..Thanks

jay@moduscreate.com
2 Jun 2009, 9:56 AM
store.reader.employeeGroup

mjlecomte
2 Jun 2009, 5:55 PM
You might be interested in:
http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Ext.data.JsonReader&member=jsonData

Another one that may hold some interest:
http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Ext.data.Field&member=convert

Also, if you're not aware, there's a FAQ dedicated to grids (see my signature), that may be of some use.

Dariusz Budynek
9 Jul 2009, 1:49 PM
Hi.
Sorry. My English is poor.



json code
{"success":true,"rows":[{"pr_ID":"600",...}],"row_count":"37","appname":"yes"}


myReaderProducts = new Ext.data.JsonReader({
root: 'rows',
totalProperty: 'row_count',
id: primaryKeyProducts,
appname: 'appname'
},
myRecordObjProducts
);

dsProducts = new Ext.data.GroupingStore({
proxy: new Ext.data.HttpProxy({
url: '?q=json/products/adm/getProducts/',
method: 'POST'
}),
reader: myReaderProducts
});

dsProducts.load({
params: {
start: 0,
limit: 30
}
});

var appnameValue = dsProducts.reader.appname;


var appnameValue = dsProducts.reader.appname; <- undefined

Why?

mjlecomte
9 Jul 2009, 3:59 PM
Try:


var appnameValue = dsProducts.reader.meta.appname;

Dariusz Budynek
10 Jul 2009, 2:01 AM
Thanks. Yes.
var appnameValue = dsProducts.reader.meta.appname; -> return "appname"

my json -> "appname":"yes"

I want to be
var appnameValue = "yes"

do not know how to do?

I read:
http://extjs.com/forum/showthread.php?t=70143
http://extjs.com/forum/showthread.php?t=72841

Condor
10 Jul 2009, 2:14 AM
1. The value is only available AFTER the store is loaded.
2. Examine the jsonData of the reader.


dsProducts.load({
params: {
start: 0,
limit: 30
},
callback: function(){
var appnameValue = dsProducts.reader.jsonData.appname;
}
});

Dariusz Budynek
10 Jul 2009, 3:06 AM
Thanks. Ok.

mjlecomte
10 Jul 2009, 5:40 AM
You might be interested in:
http://extjs.com/deploy/ext-3.0.0/docs/?class=Ext.data.JsonReader&member=jsonData

Another one that may hold some interest:
http://extjs.com/deploy/ext-3.0.0/docs/?class=Ext.data.Field&member=convert

Also, if you're not aware, there's a FAQ dedicated to grids (see my signature), that may be of some use.

That's where this post would hopefully help out.