Code:
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
Ext.onReady(function(){
Ext.define('Magnet',{
extend: 'Ext.data.Model',
fields: [
{ name: 'id', mapping: '@id' },
'title', 'contributor', 'city', 'country_id'
],
associations: [{ type: 'hasOne', model: 'Country' }],
proxy: {
type: 'ajax',
url: '/resources/xml/magnetic.xml',
reader: {
type: 'xml',
root: 'magnets',
record: 'magnet'
}
}
});
Ext.define('Country',{
extend: 'Ext.data.Model',
fields: [
{ name: 'id', mapping: '@id' }, 'name', 'continent', 'flag'
],
proxy: {
type: 'ajax',
url: '/resources/xml/magnetic.xml',
reader: {
type: 'xml',
root: 'countries',
record: 'country'
}
},
});
// create the Magnet Data Store
var magnetStore = Ext.create('Ext.data.Store', {
model: 'Magnet',
autoLoad: true
});
// create the grid
var grid = Ext.create('Ext.grid.Panel', {
store: magnetStore,
columns: [
{text: "ID", flex: 1, dataIndex: 'id'},
{text: "Title", width: 180, dataIndex: 'title', sortable: true},
{text: "Contributor", width: 180, dataIndex: 'contributor', sortable: true},
{text: "City", width: 180, dataIndex: 'city', sortable: true},
{text: "Country", width: 180, dataIndex: 'country_id', sortable: true,
renderer: function(value, metaData, record, row, col, store, gridView){
record.getCountry( function(country, operation){
// always returns the first country (USA)
} );
debugger;
}
}
],
renderTo:'example-grid',
width: 800,
height: 200
});
});
unfortunately record.getCountry always returns the first country from the XML.