PDA

View Full Version : Load remote data associated with local data.



franc0is
2 May 2011, 12:49 AM
Hello,

Here is my model:


ctapp.models.Server = Ext.regModel('Server', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'host', type: 'string'},
{name: 'username', type: 'string'},
{name: 'password', type: 'string'},
{name: 'sessionid', type: 'string'},
{name: 'version', type: 'string'}
],
associations: [
{type: 'hasMany', model: 'Camera', name: 'cameras'}
],
proxy: {
id: 'server',
type: 'localstorage'
}
});

ctapp.models.Camera = Ext.regModel('Camera', {
fields: [
{name: 'id', type: 'int'},
{name: 'server_id', type: 'int'},
{name: 'name', type: 'string'}
],
associations: [
{type: 'belongsTo', model: 'Server'}
]
});
The server store is locally filled in by the user, never sent to the server and save with localstorage.
Cameras are on the server.

I added listeners (load,add) to the server store and when a server is added/loaded, I manually request the server with a Ext.util.JSONP.request to get the camera list.

My question is: Is there a way to automatically load/unload cameras when a server is created/destroyed ?

Thanks