Salva
22 Dec 2010, 1:08 AM
Let's say I have a simple hasMany relation such as the one in the docs (using localstorage):
Ext.regModel('Product', {
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'name', type: 'string'}
],
proxy: {
type: 'localstorage',
id: 'myapp-Products'
}
});
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],
hasMany: {model: 'Product', name: 'products'},
proxy: {
type: 'localstorage',
id: 'myapp-Users'
}
});
When I load a User model, user.data.products is an empty array. I can access the related data (products in the previous example) through the user.products(), after calling user.products().load(). However, user.data.products keeps being an empty array. Thus, creating a simple template such as:
myTemplate = new Ext.XTemplate( '<tpl for=".">' +
' <h2>{name}</h2>' +
' Products:' +
' <ul>' +
' <tpl for="products"><li>{name}</span></li></tpl>' +
' </ul>' +
'</tpl>');
renders no products when called with the user object.
Of course, when I call user.products().load() I could manually insert the elements in the .products() store into the user.data.products array, but it sounds like I big ugly hack. Is there a proper/better way to render related data with a template? (or to load it into the model object).
Thanks,
Salva.
Ext.regModel('Product', {
fields: [
{name: 'id', type: 'int'},
{name: 'user_id', type: 'int'},
{name: 'name', type: 'string'}
],
proxy: {
type: 'localstorage',
id: 'myapp-Products'
}
});
Ext.regModel('User', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
],
hasMany: {model: 'Product', name: 'products'},
proxy: {
type: 'localstorage',
id: 'myapp-Users'
}
});
When I load a User model, user.data.products is an empty array. I can access the related data (products in the previous example) through the user.products(), after calling user.products().load(). However, user.data.products keeps being an empty array. Thus, creating a simple template such as:
myTemplate = new Ext.XTemplate( '<tpl for=".">' +
' <h2>{name}</h2>' +
' Products:' +
' <ul>' +
' <tpl for="products"><li>{name}</span></li></tpl>' +
' </ul>' +
'</tpl>');
renders no products when called with the user object.
Of course, when I call user.products().load() I could manually insert the elements in the .products() store into the user.data.products array, but it sounds like I big ugly hack. Is there a proper/better way to render related data with a template? (or to load it into the model object).
Thanks,
Salva.