1. #1
    Ext User
    Join Date
    Sep 2007
    Posts
    64
    Vote Rating
    0
    bluesapphire is on a distinguished road

      0  

    Question 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:

    Code:
    ({"rights": "No Rights", "total":"2","results":[{"id":"10","c_code":"US","country":"United States"},{"id":"11","c_code":"UK","country":"United Kingdom"}]})
    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.

    Can someone help me in this regards

    Thanks in advance

  2. #2
    Ext User
    Join Date
    Jan 2008
    Posts
    70
    Vote Rating
    0
    NeonMonk is on a distinguished road

      0  

    Default


    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')); 

  3. #3
    Ext User
    Join Date
    Sep 2007
    Posts
    64
    Vote Rating
    0
    bluesapphire is on a distinguished road

      0  

    Question


    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.

  4. #4
    Ext User
    Join Date
    Sep 2007
    Posts
    64
    Vote Rating
    0
    bluesapphire is on a distinguished road

      0  

    Question


    Still waitng for some pin point solution....

    Thanks in advance

  5. #5
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    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.

  6. #6
    Ext JS Premium Member NoahK17's Avatar
    Join Date
    Apr 2008
    Location
    Atlanta, GA
    Posts
    518
    Vote Rating
    1
    NoahK17 is on a distinguished road

      0  

    Default


    I get an error: [Break on this error] alert(record.get('rights'));

    record is not defined.
    Noah
    Senior Web Developer
    NBA.com

  7. #7
    Ext User
    Join Date
    Sep 2007
    Posts
    64
    Vote Rating
    0
    bluesapphire is on a distinguished road

      0  

    Question


    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:

    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................................
    Following is JSON output:

    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

  8. #8
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    I see no point at which the var 'record' is defined.