我已经看到每次我回到主页时都会调用路由器中的函数初始化,而不是在应用程序启动时调用一次。为什么?
var AppRouter = Backbone.Router.extend({
routes: {
"": "home",
"user/:id":"userDetails",
},
initialize: function(){
this.update_my_activity();
},
home: function() {
if (Parse.User.current()) {
console.log("loggato");
var user=new Person();
user.savePosition();
new BarraScreamView();
new MenuView();
var self=this;
console.log("inrouterhome");
Models.utenti = new Usercollection();
Models.utenti.fetch({
success: function(object) {
console.log(object);
var page=new Homelistuser({model:object});
self.changePage(page);
},
error: function(amici, error) {
}
});
} else
new LoginView();
}
changePage: function (page) {
this.update_my_activity();
$('#pagina').empty();
page.render();
$('#pagina').append($(page.el));
},