以下按钮单击仅在页面加载时有效,在路由后无效。1)显示默认页面 2)单击“单击此处”按钮(此工作) 3)单击其他按钮进行路由(无需重新加载页面,清除内容,并创建一个新视图提供选项以路由回默认页面) 4) 单击选项以恢复默认值。5)无需重新加载,再次重新绘制默认页面。6)单击“单击此处”按钮(这不起作用)
这是代码
var LPRouter = Backbone.Router.extend({
initialize: function (options) {
this.pageContent = $('#pageContent');
},
routes: {
'AA': 'routerMethod',
'': 'defaultMethod'
},
defaultMethod: function () {
//TODO: Set page title.
var self = this;
self.pageContent.empty();
if (!self.someView) {
self.someView = new SomeView();
self.someView.render();
}
self.pageContent.append(self.someView.el);
/*
Create a view with some link or button which will redirect to routerMethod.
*/
},
routerMethod : function() {
this.pageContent.empty();
/*
Create a view with some link or button which will redirect to defaultMethod.
*/
}
});
var SomeView = Backbone.View.extend({
tagName: "div",
className: "someclass",
initialize: function (options) {
},
hammerEvents: {
'tap .innerclass': 'someMethod'
},
someMethod: function (e) {
alert("did you click me?");
},
render: function () {
this.$el.append("<div class='innerclass'><input type='button' value='click here'/></div>");
return this;
}
});