2014-10-29 62 views
0

我有我的控制器,记录是一个计算属性。在orderBypage更改我的应用程序执行新呼叫。 该控制器完美的作品:Ember - 承诺数组

App.IndexController = Ember.ArrayController.extend({ 
    ... 
    records: function() { 
    return this.store.find("record", { 
     page: this.get("page"), 
     page_size: this.get("pageSize"), 
     order_by: this.get("orderBy") 
    }) 
    }.property("key", "orderBy", "page"), 
}) 

但是,如果我想请求时显示一个沙漏:

App.IndexController = Ember.ArrayController.extend({ 
    ... 
    records: function() { 
    this.showHourglass(); 
    return this.store.find("record", { 
     page: this.get("page"), 
     page_size: this.get("pageSize"), 
     order_by: this.get("orderBy") 
    }).then(function(records) { 
     this.hideHourglass(); 
     return records; 
    }) 
    }.property("key", "orderBy", "page"), 
}) 

我得到这个错误: Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed {_id: 59, _label: undefined, _state: undefined, _result: undefined, _subscribers: }

我怎样才能解决这个问题? 感谢

编辑: 在我的模板有一个循环,在物业:

{{#each records}} 
    ... 
{{/each} 

回答

0

这是监守this.store.find("record")返回ArrayPromise。但是因为你正在链接一个新的.then,所以返回的值只是一个常规的承诺,不能被迭代。

App.IndexController = Ember.ArrayController.extend({ 
    ... 
    records: function() { 
    this.showHourglass(); 
    var promiseArray = this.store.find("record", { 
     page: this.get("page"), 
     page_size: this.get("pageSize"), 
     order_by: this.get("orderBy") 
    }) 

    promiseArray.then(function(records) { 
     this.hideHourglass(); 
    }) 

    return promiseArray; 
    }.property("key", "orderBy", "page"), 
}) 
+0

现在感谢它的工作! – Griffosx 2014-10-29 13:06:41