更新时间:2023-10-29 16:42:10
发送
和 sendAction
街道,可以说,你可以发送一个推迟的动作,并期望它解决/拒绝它。
send
and sendAction
are one way streets, that being said, you can send a defer to the action and expect it to resolve/reject it.
var defer = Ember.RSVP.defer();
defer.promise.then(function(resolvedValue){
alert(resolvedValue);
});
setTimeout(function(){
defer.resolve('hello world');
},2000);
你的样子看起来有点像这样
Yours would look a bit like this
var defer = Ember.RSVP.defer(),
self = this;
defer.promise.then(function(){
self.closeModal();
},
function(){
alert('error');
});
this.sendAction('save', defer);
保存操作
actions: {
save: function(defer){
// if succeeded
defer.resolve();
// or if failure occurs
defer.reject();
}
}
小心,你想确保你不要不要剔除拒绝的路线,你会讨厌在这里停留模式,因为保存失败,没有失败的方法。
Be careful, you want to make sure you don't leave out the reject route, you'd hate to have the modal stuck up there because the save failed and there wasn't a failure method.
对不起我没有t转换成咖啡脚本,我想你会理解或转换和理解,我不会给你一个错误的答案。
Sorry I didn't convert to coffee script, I figure you'll either understand or convert and understand and I won't have given you a wrong answer.