我将 Ember.js 与 Phonegap 相结合,在这里您可以看到 Confirm API。但问题是我无法从这个事件驱动函数 onConfirm
..
this.transitionTo('index')
有什么想法吗?
App.MainRoute = Ember.Route.extend({
actions:{
abort: function(){
navigator.notification.confirm(
'Sind sie sicher ? ',
onConfirm,
'Abbrechen',
['NEIN','JA']
);
function onConfirm(buttonIndex) {
if (buttonIndex == 2){
this.transitionTo('index');
}
}
//this.transitionTo('index');
}
}
})
最佳答案
可变范围。 this
作用于您的 onConfirm
函数,但您需要将它作用于外部上下文:
function onConfirm(buttonIndex) {
if (buttonIndex == 2){
this.transitionTo('index');
}
}.bind(this) // <-- scope "this" so you can transition
如果您需要旧版浏览器支持,您也可以这样做:
var _self = this;
function onConfirm(buttonIndex) {
if (buttonIndex == 2){
_self.transitionTo('index');
}
}
关于javascript - Ember.js - 无法使用 this.transitionTo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519963/