ExtJS MVC 機能を備えた ExtJS 4.0.7 を使用しています。hasMany
私は親モデルを持っていbelongsTo
ます。
子供たちにアクセスする正しい方法は何ですか? parent.children().data.items[0].data
(とは対照的に)通過するparent.data.children[0]
と、不要なプロパティがありますMyApp.model.parent_id
。また、日付の保存方法の違いにも気付きました。
まず、親の定義を次に示します。したがって、親は多くの子供を持つことになります。
Ext.define('MyApp.model.Parent', {
extend : 'Ext.data.Model',
fields : [ 'id' ],
hasMany : [ {
model : 'MyApp.model.Child',
name : 'children'
}],
proxy : {
type : 'direct',
api : {
create : Parents.create,
read : Parents.read,
update : Parents.update,
destroy : Parents.destroy
}
}
});
そして、それぞれの子は親に属します。
Ext.define('MyApp.model.Child', {
extend : 'Ext.data.Model',
fields : [ 'id', {
name : 'validFrom',
type : 'date',
dateFormat : 'time'
} ],
belongsTo : 'Parent'
});
コントローラーに親をロードします。
this.getParentModel().load(id, {
scope : this,
success : function(parent) {
// the party looks good here when logged to console
console.log(parent);
this.updateStore(parent);
}
});
コンソールで親を調べると、次のことがわかります。
console.log(parent.data.children[0])
:
コンソール出力:
Object
id: 3
validFrom: -1767225600000
__proto__: Object
console.log(parent.children().data.items[0].data)
:
コンソール出力:
Object
id: 3
MyApp.model.parent_id: 209 // why is that here?
validFrom: Thu Jan 01 1914 01:00:00 GMT+0100 (Central European Standard Time)
__proto__: Object