【问题标题】:Getting undefined for findByfindBy 未定义
【发布时间】:2016-08-17 20:36:09
【问题描述】:

Ember findBy 方法返回 undefined,我是 ember 新手,无法弄清楚我做错了什么。通过 Ember Inspector 查看时,我看到 useraccount 数据存在于商店中。使用 2.7.0 版本的 ember 和 ember 数据。

this.get('store').findRecord('user', userId,{'include': 'accounts'}).then((user) => {
      this.set('currentUser', user);
      return user.get('accounts');
    }).then((accounts) =>{
      this.set('allAccounts', accounts);
      let account = accounts.findBy('primary');
      this.set('currentAccount',account);
      resolve();
    }).catch((error) => {
      reject(error);
    });

【问题讨论】:

  • 您已经在调试器中验证了其中一个帐户的primary 属性设置为true
  • 是的,我可以验证它的存在。
  • 我认为你需要添加一个截图,accounts 的样子。

标签: ember.js ember-data undefined findby


【解决方案1】:

你试过这样吗?

accounts.findBy('primary', true);

【讨论】:

    【解决方案2】:

    accounts 不包含任何具有primary 属性的对象时,将返回undefined。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      相关资源
      最近更新 更多