admin 管理员组文章数量: 1086019
I have Person model, it contains id, first_name, last_name etc and merital_id field. I also have Merital model contains only 2 field: id and title. Server responses JSON like:
{
success: true,
items: [
{
"id":"17",
"last_name":"Smith",
"first_name":"John",
...
"marital_id":1,
"marital": {
"id":1,
"title":"Female"
}
},
...
]
}
So how can I connect my models with association? I still can use record.raw.merital.title in my column.renderer, but I cannot use such fields in templates like {last_name} {first_name} ({merital.title}). What king of association do I need to use, I tryed belongsTo, but when I try to use record.getMarital() I get an error "no such method on record".
I use extjs 4
I have Person model, it contains id, first_name, last_name etc and merital_id field. I also have Merital model contains only 2 field: id and title. Server responses JSON like:
{
success: true,
items: [
{
"id":"17",
"last_name":"Smith",
"first_name":"John",
...
"marital_id":1,
"marital": {
"id":1,
"title":"Female"
}
},
...
]
}
So how can I connect my models with association? I still can use record.raw.merital.title in my column.renderer, but I cannot use such fields in templates like {last_name} {first_name} ({merital.title}). What king of association do I need to use, I tryed belongsTo, but when I try to use record.getMarital() I get an error "no such method on record".
I use extjs 4
Share Improve this question asked Jul 19, 2012 at 9:06 Luft-onLuft-on 1791 silver badge13 bronze badges1 Answer
Reset to default 8You should be using ExtJS Models, and Associations, in particular the HasOne association.
Documentation:
http://docs.sencha./ext-js/4-1/#!/api/Ext.data.association.HasOne
Example:
http://jsfiddle/el_chief/yrTVn/2/
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [
'id',
'first_name',
'last_name'
],
hasOne: [
{
name: 'marital',
model: 'Marital',
associationKey: 'marital' // <- this is the same as what is in the JSON response
}
],
proxy: {
type: 'ajax',
url: 'whatever',
reader: {
type: 'json',
root: 'items' // <- same as in the JSON response
}
}
});
本文标签: javascriptExtjs hasone associationStack Overflow
版权声明:本文标题:javascript - Extjs hasone association - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743997076a2515774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论