问题
I have the following code which I expect to return [1000] but returns [undefined]:
this.get('details').getEach('gross_total')
But
this.get('details')[0].get('gross_total')
does work and returns 1000.
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')
回答1:
I have seen this issue when prototyping require.js use for loading my app. Using ember.js 1.0.0-rc.1.
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.
So the answer seems to be to make sure only a single ember.js copy is loaded within the browser window context.
来源:https://stackoverflow.com/questions/16773229/emberjs-geteach-method-does-not-work-as-expected