I am building a shopping ca开发者_如何学运维rt using backbone.js . When some one clicks on 'add to cart' I am making an ajax call using jQuery. Backend is rails. In response I get the new json value for the cart. However if I display the cart view then car view comes up , however the url does not change.
To make the url change I after receiving the response from jQuery I need to do something so that router catches the new url and things proceed from there.
How do I navigate to the #cart
url?
You can update the URL by calling the navigate method on your router, like this:
router.navigate('cart');
Most likely your view doesn't have access to the router you can do this:
Backbone.history.navigate('cart', {trigger:true}); // router handles view change
Backbone.history.navigate('cart'); // only url is updated
精彩评论