87,910
社区成员
发帖
与我相关
我的任务
分享
AppRouter = Backbone.Router.extend({
routes: {
'': 'nav',
'!gongjiao/:step': 'goStep'
},
nav: function(){
var Step1 = Backbone.View.extend({
el: '.step1',
initialize: function() {
},
events: {
'click .button', 'taped' //当前el子元素的一些事件绑定
},
taped: function() {
}
});
var step1 = new Step1();
},
goStep: function(step) {
var Step2 = Backbone.View.extend({
el: '.step2',
initialize: function() {
},
events: {
'click a', 'taped' //当前el子元素的一些事件绑定
},
taped: function() {
}
});
var step2 = new Step2();
}
});
window['app_router'] = new AppRouter;
Backbone.history.start();
上面的一个view对应一个hash,每当hash变化就切换到相对应view的那个界面,切换界面的show,hide之类的方法就不写了。现在主要问题时,当hash来来回回多次变换,routes下相对应的方法被多次执行,相对应的view也多次被实例化后,view相对应的界面岂不是多次被重复渲染以及el子元素多次绑定事件。这个如何解决?