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?
Your second suggested solution makes the most sense, you could then instantiate your view passing that model to the constructor.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.