I have a backbone js application I have some filters on a view. Is there any way to change route once I change filters on view
Asked
Active
Viewed 1,012 times
1
-
What do you mean change route? – blockhead Jun 10 '11 at 14:25
-
When I change filters I want the filters to be part of the url , so the backbone can automatically handle the hashchange, I dont have to re-render the view – boredmgr Jun 10 '11 at 15:27
1 Answers
2
You can call "saveLocation" in your controller with the hash location you want to save. This will add an entry in the history for that location.
You can also do window.location.hash = "xxx" but saveLocation is how backbone was designed.

Julien
- 9,216
- 4
- 37
- 38
-
-
In our stuff, we really minimize what we do in views; favoring instead to defer to a controller. So we would have the view trigger an event to a controller. At that point, the controller then would have access to the saveLocation method. On a different note, I wasn't sure if your view was reacting to the filter. If so, a controller might do that by using the above-mentioned event and modifying the underlying model or collection. Then the view could be bound to the change event and refresh itself. – Bill Eisenhauer Jun 11 '11 at 02:06
-
@Bill, How do u create model for a view, if your view needs to be created using data from different DB collection ( I m using MongoDB) ? – boredmgr Jun 11 '11 at 04:53
-
You create a model possibly with results returned from your server where the model has attributes and possibly associations. You pass a model into a view upon creation. – Bill Eisenhauer Jun 11 '11 at 04:59
-
-
@Bill , used the following approach and seems this is wht I was looking for http://stackoverflow.com/questions/5946057/backbone-js-collection-get-vars – boredmgr Jun 11 '11 at 10:10
-
Which answer did you use off of that question? Consider giving it an upvote since all answers sit at zero. That might help someone else who is not sure which approach to use. Glad to be of help. – Bill Eisenhauer Jun 11 '11 at 13:40