emberjs getEach方法无法按预期工作 [英] emberjs getEach method does not work as expected
问题描述
我有以下代码,希望返回[1000],但返回[undefined]:
I have the following code which I expect to return [1000] but returns [undefined]:
this.get('details').getEach('gross_total')
但是
this.get('details')[0].get('gross_total')
起作用并返回1000。
does work and returns 1000.
我现在正在使用rc3。
I am using rc3 right now. The same code in rc1 worked fine.
我的持久层取自于话语。相关模型如下。发票有很多详细信息
My persistence layer is taken from discourse. The relevant models are below. Invoice has_many details
App.Invoice = App.Model.extend App.Commentable,
invoice_number: App.Attr('string')
description: App.Attr('string')
issue_date: App.Attr('date')
due_date: App.Attr('date')
contact: App.BelongsTo('App.Contact', "contacts")
details: App.HasMany('App.InvoiceDetail', "detail_ids")
payments: App.HasMany('App.Payment', "payment_ids")
invoice_status: App.Attr('string')
comments: App.HasMany('App.Comment', "comment_ids")
App.InvoiceDetail = App.Model.extend App.DestroyableChild,
detail_no: App.Attr('int')
description: App.Attr('string')
quantity: App.Attr('float')
unit_price: App.Attr('currency')
consumption_tax_rate: App.Attr('float')
vat_rate: App.Attr('float')
discount_type: App.Attr('string')
discount_value: App.Attr('currency')
product: App.BelongsTo('App.Product', 'products')
推荐答案
在原型require.js用于加载我的应用程序时,我已经看到了这个问题。使用ember.js 1.0.0-rc.1。
I have seen this issue when prototyping require.js use for loading my app. Using ember.js 1.0.0-rc.1.
我将其追溯到拥有两个ember.js脚本实例(每个脚本实例包含其自己的不同Ember.META_KEY) ),这暗示了不合逻辑的行为。
I traced it down to having two ember.js script instances (each of which contains its own different Ember.META_KEY) which implied the illogical behavior.
所以答案似乎是确保在浏览器中仅加载单个ember.js副本窗口上下文。
So the answer seems to be to make sure only a single ember.js copy is loaded within the browser window context.
这篇关于emberjs getEach方法无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!