Code:
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {
User = Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'email', type: 'string'},
{name: 'password', type: 'password'},
{name: 'addresses', type: 'array' }
],
hasMany: {model: "Address", name: "address"}
});
Address = Ext.regModel('Address', {
fields: [
{name: 'id', type: 'int'},
{name: 'userId', type: 'int'},
{name: 'type', type: 'string'},
{name: 'street', type: 'string'}
],
belongsTo: {model: 'User', name: 'user' }
});
var userData = {
users: [
{id: 1, email: 'test1@here.com', password: 'secret1'},
{id: 2, email: 'test2@here.com', password: 'secret2'},
{id: 3, email: 'test3@here.com', password: 'secret3'}
]
};
var addressData = {
addresses: [
{id: 1, userId: 1, type: 'home', street: '123 Main St.'},
{id: 2, userId: 1, type: 'work', street: '3328 Primrose Lane.'},
{id: 3, userId: 2, type: 'home', street: '47 Baltic Ave.'},
{id: 4, userId: 3, type: 'home', street: '757 Unicorn Place'},
{id: 5, userId: 3, type: 'work', street: '10 Claire Rd.'}
]
};
var addressStore = new Ext.data.Store({
autoLoad: true,
model: 'Address',
data: addressData,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'addresses'
}
}
});
var dview = new Ext.DataView({
store: new Ext.data.Store({
autoLoad: true,
model: 'User',
data: userData,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
}),
tpl: new Ext.XTemplate(
'<p>Users</p>',
'<tpl for=".">',
'<div class="lineitem">id: {id} {email} </div>',
'<ul>',
'<tpl for="Address">',
'<li>{type} {street}</li>',
'</tpl>',
'</ul>',
'</tpl>'
),
fullscreen: true,
itemSelector: 'div.lineitem'
});
}
});