【问题标题】:emberjs getEach method does not work as expectedemberjs getEach 方法无法按预期工作
【发布时间】:2013-05-27 12:27:42
【问题描述】:

我有以下代码,我希望返回 [1000] 但返回 [undefined]:

this.get('details').getEach('gross_total')

但是

this.get('details')[0].get('gross_total')

确实有效并返回 1000。

我现在正在使用 rc3。 rc1 中的相同代码运行良好。

我的持久层取自话语。相关型号如下。发票有_很多细节

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')

【问题讨论】:

  • 假设 this.get('details') 是数据库中的记录数组,你能粘贴细节模型定义的代码吗?
  • 这就是它变得棘手的地方,我并没有完全展示要展示的内容。我有一个持久层的自定义实现,主要取自话语。我已经更新了我上面的问题,但不幸的是,我认为这并不是很有帮助。

标签: ember.js


【解决方案1】:

我在制作用于加载我的应用的 require.js 的原型时看到了这个问题。使用 ember.js 1.0.0-rc.1。

我追查到有两个 ember.js 脚本实例(每个都包含自己不同的 Ember.META_KEY),这暗示了不合逻辑的行为。

所以答案似乎是确保在浏览器窗口上下文中只加载一个 ember.js 副本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多