Reputation: 2048
I have the View containing some button. When that View becomes activated it should take the some URL parameter (in my case -- site id) and set it to the button attribute "data-site_id". There is a router too in the app. But I don't know how to implement it with the best way. Till now I see 3 supposed solutions:
Extract site id from URL hash. URL is build by such a pattern:
"sites/edit/:id(/:tab)": "editSite",
the question is -- may I use here a router itself (and, if yes then how?) or can not, and should parse it with common JS way? Of course, router & view are two different objects and located in different files/scopes.
(function(app, $, config, _) { var Model = new app.modelName(); var Router = app.Router = Backbone.Router.extend({ routes: { "": "start", //.... "sites/edit/:id(/:tab)": "editSite", //... }, //.... editSite: function(id, tab){ Model.set('site_id', id); } //.... })(window.Application, jQuery, window.chatConfig, _);
after that I can extract the site id from model in any time I want
So what is your advice?
Upvotes: 0
Views: 37
Reputation: 749
Your second suggested solution makes the most sense, you could then instantiate your view passing that model to the constructor.
See http://backbonejs.org/#View-constructor
Upvotes: 1