我正在努力鏈接Ember控制器中的承諾。在Ember中使用承諾
爲了說明我做了問題的例子在JSBIN here
這裏也包括灰燼代碼:
App.IndexController = Ember.Controller.extend({
result_of_request: 'nothing',
first_request: function() {
// create a promise which is immediately resolved
var promise = new Ember.RSVP.Promise(function(resolve, reject){
resolve("first resolved");
});
// once the promise has resolved it should call the next function?
promise.then(function(data) {
// does log the data (has resolved)...
console.log("data is : " + data);
// but neither this
this.set("result_of_request", "first");
// nor this work
second_request();
});
}.property(),
second_request: function() {
console.log("second request");
}.property()
});
任何意見,將不勝感激。
'this'不是控制器內部的回調,'second_request'是方法(屬性)而不是函數(變量)。 – Bergi