Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  184] [ 1]  / answers: 1 / hits: 29559  / 13 Years ago, thu, september 22, 2011, 12:00:00

My view is set up as below. simple.



var ItemView = Backbone.View.extend({
tagName : li,

events : {
click : display
},

display : function() {
//app.navigate('item'); // take me to my route!
}
});


And I have my router



var App = Backbone.Router.extend({

routes: {
: index,
item : view_item
},

index: function() {
alert('hi!');
},

view_item: function() {
alert('bye!');
}
});

app = new App();
Backbone.history.start();


Now, when I click on ItemView, it should run display method and I want the display method to take me to the route I specified in routes item.



Is this possible? I thought navigate function will work, but it doesn't. How could I achieve this?


More From » backbone.js

 Answers
1
 display : function() {
app.navigate('item', true);
}


You need the second parameter set to true.



From the Backbone documentation:




navigaterouter.navigate(fragment, [triggerRoute])
Whenever you reach a point in your application that you'd like to save as a URL, call navigate in order to update the URL. If you wish to also call the route function, pass triggerRoute.



[#89978] Tuesday, September 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brodyfrancisi

Total Points: 1
Total Questions: 102
Total Answers: 89

Location: Marshall Islands
Member since Mon, May 31, 2021
3 Years ago
brodyfrancisi questions
;