Tuesday, 6 August 2013

Insert timer function in router backbone

Insert timer function in router backbone

I need insert in my router a function that works every specified
time(example 5 secs), but the problem is that the counter restart count
everytime I comeback to the home. If i open my application the counter
starts and even if i go to another page it count correctly,but if i return
to home the counter is restart.I've tried with bind and unbind but doesn't
work.
This is my router:
var AppRouter = Backbone.Router.extend({
routes: {
"": "home",
"user/:id":"userDetails",
"settings":"settings",
"friends":"friends",
"mailbox":"mailbox",
"landscape":"landscape"
},
initialize:function(){
$(window).bind('onload',
setInterval(function(){alert("Hello")},5000));<---------
$(window).unbind('onload'); <---------
},
home: function() {
if (Parse.User.current()){
var user=new Person();
user.savePosition();
new BarraScreamView();
new MenuView();
}
else
new LoginView();
},
userDetails: function (id) {
console.log(id);
console.log(Models.utenti.get(id));
var page=new UserDetailView({model:Models.utenti.get(id)});
this.changePage(page);
},

No comments:

Post a Comment