[英]ExtJS: Vallid model with child, can't use HasOne as I have no association ID?
[英]Extjs hasone association
我有Person模型,它包含id,first_name,last_name等和merital_id字段。 我也有Merital模型只包含2個字段:id和title。 服務器響應JSON如:
{
success: true,
items: [
{
"id":"17",
"last_name":"Smith",
"first_name":"John",
...
"marital_id":1,
"marital": {
"id":1,
"title":"Female"
}
},
...
]
}
那么如何將我的模型與關聯聯系起來呢? 我仍然可以在我的column.renderer中使用record.raw.merital.title,但我不能在像{last_name} {first_name}({merital.title})這樣的模板中使用這些字段。 我需要使用什么樣的關聯王,我嘗試使用belongsTo,但是當我嘗試使用record.getMarital()時,我得到一個錯誤“記錄中沒有這樣的方法”。
我使用extjs 4
您應該使用ExtJS模型和關聯,特別是HasOne關聯。
文檔:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.association.HasOne
例:
http://jsfiddle.net/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
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.