vendredi 16 mai 2014

How to dynamicaly load the associated record

Hello

I have some questions about the loading of associations (with code and with the new bind system).

I have two models with a reference (see example 1). How to easily load my association with code ? When the association give me a store (one-to-many) I have the load method, but when the association give me an object (many-to-one) how to load the record ? Use the Model's static load ?


My secondary question is the same with the new bind system and a ViewModel. I have a simple view (see example 2). I want to load the associated record of the selected item. Nothing happen when i use bind. I had to use an intermediate links to load my data. How to load my association when I bind it ?


Thanks,

Romain


Example 1 (models):



Code:



Ext.define('Altgr.model.Model', {
extend: 'Ext.data.Model',

requires: [
'Altrgr.proxy.Apiv3Proxy'
],

idProperty: 'code',

fields: [
{
name: 'code',
type: 'string'
},
],

proxy: {
type: 'apiv3proxy',
}
});


Ext.define('Altgr.model.Image', {
extend: 'Altgr.model.Model',

requires: [
'Altgr.model.ImageData',
],

fields: [
{ name: 'name', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'imagedata_code', reference: {
type: 'ImageData',
role: 'imagedata',
inverse: 'image'
}},
],
});


Ext.define('Altgr.model.ImageData', {
fields: [
{ name: 'path', type: 'string' },
],
});

Example 2 (view and viewmodel):


Code:



Ext.define('ImagesBrowser.view.main.Main', {
extend: 'Ext.container.Container',

requires: [
"Altgr.widget.ImageView"
],

xtype: 'app-main',

controller: 'main',
viewModel: {
type: 'main'
},

session: true,

layout: {
type: 'border'
},

items: [{
xtype: 'panel',
bind: {
title: '{name}'
},
region: 'west',
width: 250,
split: true,
items: [
{
xtype: 'grid',
flex: 1,
bind: '{images}',
reference: 'imageslist',
session: true,
columns: [
{ text: 'Name', dataIndex: 'name', flex: 1 }
]
}]
},{
layout: 'fit',
xtype: "imageview",
bind: "{imageslist.selection.imagedata}"
}]
});


Ext.define('ImageBrowser.view.main.MainModel', {
extend: 'Ext.app.ViewModel',

requires: [
"Altgr.model.Image",
],

alias: 'viewmodel.main',

data: {
name: 'ImagesBrowser',
},

stores: {
images: {
model: 'Altgr.model.Image',
autoLoad: true,
},
}
});




Aucun commentaire:

Enregistrer un commentaire