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