【发布时间】:2015-06-14 11:31:04
【问题描述】:
我正在尝试向我的模型返回一个数组承诺,以便我可以遍历我的模板中的结果。我需要联系产品作为承诺数组而不是承诺对象返回。
型号:
App.ContactEditorRoute = Ember.Route.extend({
model: function (params) {
return Ember.RSVP.hash({
contact: this.store.find('contact', params.id),
/*need this to return array not an object which is currently does*/
contactproducts: this.store.find('contactproduct',params.id),
products: this.store.find('product')
})
}
模板:(使用标志进行标记)
each contactproduct in contactproducts
p
' quantity
contactproduct.quantity
' notes
contactproduct.note
【问题讨论】:
-
您正在按 id 搜索,当您指定资源 id 时它不会返回集合。为什么它需要是一个集合?
-
我需要能够遍历结果。每个联系人都有 0 到多个存储在联系人产品中的产品
-
如果联系人产品是联系人中的 hasMany,为什么要在 rsvp 哈希中获取它?它应该是联系模型的一部分...
标签: javascript arrays ember.js ember-data emblem.js