【发布时间】:2013-08-27 04:10:36
【问题描述】:
好的。我已经通过 Google 返回的 SO 和其他来源进行了很好的查看,但还没有找到我的问题的答案。
我有两个模型:
App.Kid = Ember.Model.extend
title: DS.attr "string"
parent: DS.belongsTo "App.Parent"
App.Parent = Ember.Model.extend
title: DS.attr "string"
kids: DS.hasMany "App.Kid"
这里的大多数问题都讨论了从侧面加载的 JSON 数据中检索 ember 数据关系,这是我能够做到的。我需要知道的是如何在创建新孩子时保存 parent_id?
目前我正在 App.KidController 中保存一个新孩子,如下所示:
App.ParentController = Ember.ObjectController.extend
needs: [ "widgets" ]
App.KidCreateController = Ember.ObjectController.extend
needs: [ "dashboard" ]
saveChild: ->
@content.get( "store" ).commit()
保存时看不到 parent_id,但是我确实得到了一个新的父对象(分配给父键),其 id 为 0。
谁能解释我在这里做错了什么?
更新 1
所以我会用我的实际情况来解释我在做什么。
一个用户有多个仪表板,这些仪表板附加了多个小部件。我的模型结构如下所示:
App.Dashboard = DS.Model.extend
title: DS.attr "string"
widgets: DS.hasMany "App.Widget"
App.Widget = DS.Model.extend
title: DS.attr "string"
type: DS.attr "string"
...
dashboard: DS.belongsTo "App.Dashboard"
【问题讨论】:
标签: ember.js ember-data