如何在计算属性中重新加载ember模型

时间:2014-08-13 09:41:03

标签: javascript ruby-on-rails node.js model-view-controller ember.js

我对Ember Controller中的计算属性有两个疑问。

  • 如何重新加载模型?
  • 我如何回复承诺?

来自Ember Controller内的计算属性。

App.MyController = Ember.ObjectController.extend({
    poll: function() {
        // Question 1
        // reload the model from server (send GET /stuff).
        return this.get('model.poll');
    }.property('model');


    second: function() {
        // Question 2
        // return a promise 
        return this.find('choices');
    }.property('model');
});

修改

我已经设置了一个使用online fake rest server的jsbin,但我无法让它工作,我将不胜感激。 http://emberjs.jsbin.com/EnOqUxe/155/edit

EDIT2

好吧你的jsbin有效,我在我的电脑上尝试了同样的事情并且ember检查员承诺标签显示了一个未决的请求,任何想法为什么?:

DS:RestAdapter#ajax GET /api/v1/games/1 Pending

VM409:161
2
Ember Inspector (Promise Trace): DS: RESTAdapter#ajax GET to /api/v1/games/1
    at new Promise (http://192.168.56.101:3000/public/assets/scripts/lib/ember/ember.js:10173:9)
    at __exports__.default.Adapter.extend.ajax (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:1828:16)
    at __exports__.default.Adapter.extend.find (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:1347:21)
    at _find (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:11883:29)
    at Ember.Object.extend.fetchRecord (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:10504:23)
    at _fetchRecord (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:10553:53)
    at Ember.Object.extend._flushPendingFetchForType (http://192.168.56.101:3000/public/assets/scripts/lib/ember-data/ember-data.js:10590:11)
    at http://192.168.56.101:3000/public/assets/scripts/lib/ember/ember.js:4536:20
    at Object.OrderedSet.forEach (http://192.168.56.101:3000/public/assets/scripts/lib/ember/ember.js:4379:14) VM409:164

0 个答案:

没有答案