-
25 Jul 2008 4:43 PM #1
How to display JsonReader data in Alert
How to display JsonReader data in Alert
Hi!
I am collecting data of a store through JSON Reader. Data received from server is in following format:
I have a button in Top Toolbar of a grid. When I click on this button, I want to display 'rights' value in alert message box. How it would be possible.Code:({"rights": "No Rights", "total":"2","results":[{"id":"10","c_code":"US","country":"United States"},{"id":"11","c_code":"UK","country":"United Kingdom"}]})
Can someone help me in this regards
Thanks in advance
-
25 Jul 2008 9:38 PM #2
http://localhost/extjs/docs/?class=Ext.data.Store
Read up on methods getAt()
Then read http://localhost/extjs/docs/?class=Ext.data.Record
get()
Eg:
PHP Code:var index = 0;
var record = randomStore.getAt(index);
alert(record.get('rights'));
-
26 Jul 2008 8:03 AM #3
Hi!
Thanks for guidance. But it is displaying 'Undefined'.
For demo, kindly visit following link :
http://vibersol.com/sitesdemo/rq/ind...admin/country/
Then click on 'Add Record' link.
-
28 Jul 2008 7:32 AM #4
Still waitng for some pin point solution....
Thanks in advance
-
28 Jul 2008 8:38 AM #5
I am not going to dig through your js files just to find the right section of code. If you want us to help you, you need to put a little bit of effort into providing the right information.
-
28 Jul 2008 9:02 AM #6
I get an error: [Break on this error] alert(record.get('rights'));
record is not defined.Noah
Senior Web Developer
NBA.com
-
28 Jul 2008 9:43 AM #7
Hi!
Following are some codes:
Data Store Code:
Variables 'murl' and 'mind' are path variables and are set.
Code:PnDataStore = new Ext.data.Store({ id: 'PnDataStore', proxy: new Ext.data.HttpProxy({ url: murl+mind+'admin/country/getData', // File to connect to method: 'POST' }), baseParams:{task: "LISTING"}, // this parameter asks for listing reader: new Ext.data.JsonReader({ // we tell the datastore where to get his data from root: 'results', totalProperty: 'total', id: 'id' },[ {name: 'IDp', type: 'int', mapping: 'id'}, {name: 'Ccode', type: 'string', mapping: 'c_code'}, {name: 'Country', type: 'string', mapping: 'country'} ]), sortInfo:{field: 'IDp', direction: "ASC"} });
Following is some of the TBAR part:
Following is JSON output:Code:,tbar: [{ id: 'buttonA' ,text: 'Add Record' ,tooltip: 'Add Record' ,iconCls:'add' ,handler: function(){ if(Ext.getCmp('buttonA').disabled) { var index = 0; var record = PnDataStore.getAt(index); alert(record.get('rights')); } else{ var index = 0; var record = PnDataStore.getAt(index); alert(record.get('rights')); } } } .......................TBAR continues................................
Code:({"rights": "No Rights", "total":"5","results":[{"id":"1","c_code":"UK","country":"United Kingdom"}, {"id":"2","c_code":"US","country":"United States"},{"id":"3","c_code":"FR","country":"France"},{"id" :"4","c_code":"CN","country":"China"},{"id":"5","c_code":"JP","country":"Japan"}]})
Hope some one will guide me in this regards
Thanks in advance
-
28 Jul 2008 9:52 AM #8
I see no point at which the var 'record' is defined.


Reply With Quote