emberjs getEach method does not work as expected

六月ゝ 毕业季﹏ 提交于 2019-12-12 06:32:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!