ember.js多模式表单:对ember数据的期望是什么?
我有典型的多式联运形式:如我的模型中所述,有许多运输单据行的运输单据:ember.js多模式表单:对ember数据的期望是什么?,ember.js,ember-data,Ember.js,Ember Data,我有典型的多式联运形式:如我的模型中所述,有许多运输单据行的运输单据: App.TransportDocument = DS.Model.extend number: DS.attr 'string' date: DS.attr 'string' transportDocumentRows: DS.hasMany('App.TransportDocumentRow') App.TransportDocumentRow = DS.Model.extend productName:
App.TransportDocument = DS.Model.extend
number: DS.attr 'string'
date: DS.attr 'string'
transportDocumentRows: DS.hasMany('App.TransportDocumentRow')
App.TransportDocumentRow = DS.Model.extend
productName: DS.attr 'string'
quantity: DS.attr 'string'
transportDocument: DS.belongsTo('App.TransportDocument')
我在控制台中编写以下脚本:
a = App.Invoice.createRecord();
a.get("invoiceRows").pushObject(App.InvoiceRow.createRecord());
a.get("store").commit();
问题是:
- 我的运输单据创建正确
- “我的运输单”行是按顺序创建的(这可能仍然不是问题),但具有错误的运输单id(运输单id:0)
DS.RESTAdapter.map 'App.TransportDocument', {
transportDocumentRows: { embedded: 'always' }
}
此选项在单个HTTP请求中提交传输文档及其行
这需要更改GET响应,包括响应哈希的
transport\u documents
键中直接包含的transport\u documents\u行
内容是否有任何额外的配置用于此关联,如:DS.WhicheverAdapterYoureUsing.map('App.TransportDocument',{transportDocumentRows:{embedded:'load}});代码>?不,没有比这更正确的行为是TransportDocument行具有新的和正确的TransportDocument\u id?不太确定。事实上,我自己也在为类似的情况而挣扎。在我的例子中,似乎我必须分多个步骤来完成:先提交父对象,然后提交子对象。@MilkyWayJoe如果需要,我有一个部分解决方案,请参见编辑