1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default Unanswered: Unable to bind record from associated data to Ext.List

    Unanswered: Unable to bind record from associated data to Ext.List


    Hi,

    I am new to ST and still learning few tricks but this time and I am having a hard time how to get records from data associations to Ext.List.

    Here's my code.

    Code:
    
    
    Code:
    			Ext.define('Place', {
    				extend: 'Ext.data.Model',
    				config: {
    					fields: ['id','name'],
    					hasMany: [
    						{
    							model: 'Location',
    							name: 'locations',
    							associationKey: 'location'
    						}
    					]
    				}
    			});
    
    			Ext.define('Location', {
    				extend: 'Ext.data.Model',
    				config: {
    					fields: [
    						{
    							name: 'address'
    						},
    						{
    							name: 'city'
    						},
    						{
    							name: 'country'
    						},
    						{
    							name: 'lat'
    						},
    						{
    							name: 'lng'
    						}
    					]
    				}
    			});
    
    
    		this.resultsStore = Ext.create('Ext.data.Store', {
    			model: 'Place',
    			config: {
    				autoLoad: false
    			       proxy: {
    		               type: 'jsonp',
    			      url: 'https://api.foursquare.com/v2/venues/suggestcompletion?ll=' + lat + ',' + lon + '&oauth_token=SECNGXU003CSP5VZMCS5VRUDB24O3TIKW3O3BF4YCKDKCG20&v=20130211',
    		              reader: {
    		                  type: 'json',
    			          rootProperty: 'response.minivenues'
    			         }
    		              },
    
    			}
    		});
    
    		this.resultsList = Ext.create('Ext.List', {
    			renderTo: this.getComponent().element.dom,
    			store: that.resultsStore,
    			margin: 2,
    			itemTpl: ['{name}', '<tpl for="locations">', ' {address} ', '{city} ', '{country}', '</tpl>']
    		});
    
    		this.resultsList.on('itemtap', function(self, index, target, record) {
    			console.log(record.get('address')); <-- this is not working returns undefined
    			that.setValue(record.get('name'), record.get('id'));
    			that.isSelectedItem = true;
    
    
    
    


    As you can see I am trying to access the "address" field from Location model which is associated to the Place model via record.get('address') through itemtap event of Ext.List. Though I am able to get a value when I just do a record.get('locations') but this returns a value like

    Code:
    
    
    Code:
    
    
    Object
    address: "Camarin Rd."
    city: "Caloocan City North"
    country: ""
    id: "ext-record-51"
    lat: 14.751034083341276
    lng: 121.03739867183924
    __proto__: Object
    
    


    I had been pounding my head what was I missing. A shed of light is very much appreciated.

    Thanks in advance.

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Any one really badly need help on this one. Let me know if something's not clear. Thanks

  3. #3
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Answers
    5
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    Does

    record.get('locations').get('address')

    work?


    Also, you shouldn't use a field called 'id' in the model. It conflicts with the internal ID that ST uses.

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Hi cyee I was able to get around of it using record.get('locations')[0].address. Value returned by get('locations') is an array so I have to index the field that I wanna pull i.e. address.

Thread Participants: 1

Tags for this Thread