【问题标题】:How to find ember store如何找到 ember 商店
【发布时间】:2014-04-10 09:30:18
【问题描述】:

我正在尝试使用 Ember 中的商店从模型中检索记录。我就是这样的

var rec = this.store.find(App.Recipient);
console.log(rec);

当我输出这个时,我得到了这个结果

Class {toString: function, __ember1397122062151_meta: Object, __ember1397122062151: "ember497", _super: undefined, constructor: function…}

我的目的是获取所有记录,以便将它们发送到服务器。还有关于如何在控制器中迭代它们的任何观点?

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    store.find 返回一个 promise,所以获取记录的方法是这样的:

    this.store.find('recipient').then(function(recipients){
      recipients.forEach(function(recipient) {
        var zip = recipient.get('zip');
      })
    });
    

    【讨论】:

    • 它返回 thisClass {toString: function, __ember1397123284435_meta: Object, __ember1397123284435: "ember437", _super: undefined, constructor: function…}
    • 如果我这样做,我会得到结果 this.get('store').find('recipient',id).then(function (recipient){ console.log( recipient.get('name')); 但我不想使用 ID。
    • 它返回给我一个类。
    • this.store.find('recipient').then(function(recipients){ console.log(recipients.get('zip')); });这样做会返回我 undefined
    • 实现了 promise 返回一个数组。首先从数组中获取一个项目,然后像我在更新的答案中那样获取 zip
    猜你喜欢
    • 2019-12-21
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 2016-09-30
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多