我在标题中有一个超链接。当用户从一个标题链接导航到另一个时我需要检查页面是否脏了,如果页面脏了,我需要显示一个模式,其中有确定和取消按钮,并且确定我需要导航到单击的标题和取消我需要留在页面中。下面是我写的示例代码。
Template:
<a href="#link1" id="link1"></a>
<a href="#link2" id="link1"></a>
HeaderView.js
..
..
ui {
"link1" : "#link1",
"link2" : "#link2",
},
events {
"click #link1" : "navigateLink1"
"click #link2" : "navigateLink2"
}
navigateLink1 : function(e) {
this.navigate(this.ui.link1, "#link1", true, e);
}
navigateLink2 : function(e) {
e.preventDefault();
this.navigate(this.ui.link2, "#link2", true, e);
}
navigate: function(uiElement, path, trigger, event) {
e.preventDefault();
if (model.isDirty() ) {
// I need to send a callback for clicking on ok button
this.callback = function() {
event.trigger();// I am getting an error saying that event.trigger is not a function.
}
new ApplicationModal(model: {callback: this.callback});
} else {
app.router.navigate(path , {trigger: trigger});
}
}
在ApplicationModal中我只是执行回调
我收到一条错误,说event.trigger在回调时调用时不是函数。让我知道如何在e.preventDefault()之后导航到新页面;