复合模型(模型中的模型),还是模型之间的手动外键关联?
我有两个模型,我想将一个模型“嵌套”在另一个模型中。有没有办法用 Sencha Touch 做到这一点?我的模型如下所示:
Ext.regModel('OuterModel', {
fields: ['name']
});
var outerStore = new Ext.data.Store({
model: 'OuterModel',
data: [
{name: 'item1'},
{name: 'item2'}
]
});
Ext.regModel('InnerModel', {
fields: ['a', 'b']
});
var innerStore = new Ext.data.Store({
model: 'InnerModel',
data: [
{a: 1, b: 5},
{a: 2, b: 5},
{a: 3, b: 3}
]
});
每个 OuterModel
需要一个关联的 InnerModel
,并且我希望能够拥有一个是内部模型的字段-我可以从中创建 Ext.List 的模型。我可以将 outerName
添加到 InnerModel
并查询 outerName
,但这感觉很草率,需要手动管理关联。
手动解决方案是我唯一的选择,还是我可以将一个模型作为另一个模型的字段?
I have two models, and I want to "nest" one within the other. Is there a way to do this with Sencha Touch? My models look like this:
Ext.regModel('OuterModel', {
fields: ['name']
});
var outerStore = new Ext.data.Store({
model: 'OuterModel',
data: [
{name: 'item1'},
{name: 'item2'}
]
});
Ext.regModel('InnerModel', {
fields: ['a', 'b']
});
var innerStore = new Ext.data.Store({
model: 'InnerModel',
data: [
{a: 1, b: 5},
{a: 2, b: 5},
{a: 3, b: 3}
]
});
Each OuterModel
needs an associated InnerModel
, and I would love to just be able to have a field that was an inner-model that I could create Ext.List
s from. I could add outerName
to InnerModel
and query on outerName
, but this feels sloppy, manually managing the association.
Is the manual solution my only option, or can I make a model a field of another model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型可以通过belongsTo 和hasMany 关联与其他模型建立关联。例如,假设我们正在编写一个处理用户、帖子和评论的博客管理应用程序。我们可以这样表达这些模型之间的关系:
请参阅文档 Ext.data.BelongsToAssociation 和 Ext.data.HasManyAssociation 了解有关关联的使用和配置的详细信息。请注意,关联也可以这样指定:
Models can have associations with other Models via belongsTo and hasMany associations. For example, let's say we're writing a blog administration application which deals with Users, Posts and Comments. We can express the relationships between these models like this:
See the docs for Ext.data.BelongsToAssociation and Ext.data.HasManyAssociation for details on the usage and configuration of associations. Note that associations can also be specified like this: