1

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

boredmgr
  • 272
  • 1
  • 7
  • 20

1 Answers1

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
  • how do i get the instance of the controller in a view? – boredmgr Jun 10 '11 at 15:26
  • 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 is there any way to pass the filter parameters to collection? – boredmgr Jun 11 '11 at 07:33
  • @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