Ext.data.association.HasOne - represents a one to one association with another model.
The owner model is expected to have
a foreign key which references the primary key of the associated model
ExtJs 4.1: Read complex json with hasOne association
By on September 15, 2012. ext-4.1.0-gplResult
Do you know?
Js Code
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
associations: [{ type: 'hasOne', model: 'Status', associationKey: 'status'}]
});
Ext.define('Status', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'title', type: 'string', mapping: 'st_title' }
]
});
Ext.onReady(function () {
var store = Ext.create('Ext.data.ArrayStore', {
model: 'User',
data: [
{ id: '1', name: 'user-1', status: { id: 2, st_title: 'disabled'} },
{ id: '2', name: 'user-2', status: { id: 1, st_title: 'active'} },
{ id: '3', name: 'user-3', status: { id: 3, st_title: 'deleted'} },
{ id: '4', name: 'user-4', status: { id: 1, st_title: 'active'} },
{ id: '5', name: 'user-5', status: { id: 3, st_title: 'deleted'} }
],
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});
Ext.widget({
xtype: 'grid',
title: 'Users',
width: 400,
height: 180,
store: store,
renderTo: 'output',
columns: [
{ text: 'id', dataIndex: 'id' },
{ text: 'name', dataIndex: 'name' },
{
text: 'status',
renderer: function (v, m, r) {
return r.getStatus().get('title');
}
}
]
});
});