鉴于这些模型:
App.TransportDocument = DS.Model.extend
number: DS.attr 'string'
date: DS.attr 'string'
printable_url: DS.attr 'string'
transport_document_rows: DS.hasMany('App.TransportDocumentRow')
App.TransportDocumentRow = DS.Model.extend
product_name: DS.attr 'string'
quantity: DS.attr 'number'
measure: DS.attr 'string'
transport_document: DS.belongsTo('App.TransportDocument')
这是我的路线:
App.TransportDocumentsRoute = Ember.Route.extend
model: -> App.TransportDocument.find()
App.TransportDocumentRoute = Ember.Route.extend
model: (params)-> App.TransportDocument.find(params.transport_document_id)
App.TransportDocumentRowRoute = Ember.Route.extend
model: -> App.TransportDocumentRow.find()
我有一个车把模板:
{{#each transport_document in controller}}
td_id: {{transport_document.id}}
{{#each transport_document_row in transport_document.transport_document_rows}}
row_id: {{id}}
{{/each}}
{{/each}}
我希望我的结果是:
td_id: 1 row_id: 1 row_id: 2 row_id: 3
td_id: 2 row_id: 3 row_id: 4 row_id: 5
td_id: 3 row_id: 8 row_id: 7 row_id: 6
但是是:
td_id: 1 row_id: row_id: row_id:
td_id: 2 row_id: row_id: row_id:
td_id: 3 row_id: row_id: row_id:
这是我的服务器对 /transport_documents 的响应
{"transport_documents":
[
{"id":1,"number":"11","date":"17/04/2013","cause":"Conto lavorazione","transport_document_row_ids":[3,2,1],"transport_document_rows":
[
{"transport_document_row":{"id":3,"transport_document_id":1,"product_name":"suola puzzle verde","quantity":"1","measure":"pz","}},
{"transport_document_row":{"id":2,"transport_document_id":1,"product_name":"lacci rossi","quantity":"2","measure":"pz"}},
{"transport_document_row":{"id":1,"transport_document_id":1,"product_name":"Rotolo di tela","quantity":"50","measure":"m"}}
]},
{"id":2,"number":"2","date":"18/04/2013","cause":"Conto lavorazione","transport_document_row_ids":[6,5,4],"transport_document_rows":
[
{"transport_document_row":{"id":6,"transport_document_id":2,"product_name":"suola puzzle verde","quantity":"1","measure":"pz"}},
{"transport_document_row":{"id":5,"transport_document_id":2,"product_name":"lacci rossi","quantity":"2","measure":"pz"}},
{"transport_document_row":{"id":4,"transport_document_id":2,"product_name":"Rotolo di tela","quantity":"50","measure":"m",}}
]},
{"id":3,"number":"3","date":"19/04/2013","cause":"Conto lavorazione","transport_document_row_ids":[9,8,7],"transport_document_rows":
[
{"transport_document_row":{"id":9,"transport_document_id":3,"product_name":"suola puzzle verde","quantity":"1","measure":"pz"}},
{"transport_document_row":{"id":8,"transport_document_id":3,"product_name":"lacci rossi","quantity":"2","measure":"pz"}},
{"transport_document_row":{"id":7,"transport_document_id":3,"product_name":"Rotolo di tela","quantity":"50","measure":"m"}}]}
我想我在路线上做错了(我在哪里定义查询以查找该文档的所有行?)但我不确定。在指南中找不到类似的东西
谢谢你