javascript - How Get ID value from router in view using backbone.js -
i have router.js , view.js
i want value of id passed router.js page in view page. how can that??
here router:
/** * created hp on 6/26/2014. */ var app = app || {}; app.router = backbone.router.extend({ routes: { '': 'index', 'color/:id': 'color' }, index: function(){ console.log("index called"); }, color: function(id){ console.log("color called"+id); //viewpage.render(id); } }); new app.router; backbone.history.start(); in view want value of id need set in html element here view /** * created hp on 6/17/2014. */
// site/js/views/library.js var app = app || {}; app.libraryview = backbone.view.extend({ el: '#ulmenu', initialize: function(options) { this.collection = new app.library(); this.collection.fetch({reset: true}); this.render(); this.listento( this.collection, 'reset', this.render ); }, events:{ 'click':'show' }, show: function(){ this.subrender(); }, render: function() { }, subrender: function() { $("#content").html("color name: "); } });
i think can seek passing arguments options
router
var app = app || {}; app.router = backbone.router.extend({ routes: { '': 'index', 'color/:id': 'color' }, index: function(){ console.log("index called"); }, color: function(id){ console.log("color called"+id); var libraryview = new libraryview({ id : id //passing alternative views initalize. }); } }); new app.router; backbone.history.start(); view
var app = app || {}; app.libraryview = backbone.view.extend({ el: '#ulmenu', initialize: function(options) { this.receivedid = this.options.id; // id catched here this.collection = new app.library(); this.collection.fetch({reset: true}); this.render(); this.listento( this.collection, 'reset', this.render ); }, events:{ 'click':'show' }, show: function(){ this.subrender(); }, render: function() { }, subrender: function() { $("#content").html("color name: "); } }); javascript backbone.js backbone-views backbone-routing
No comments:
Post a Comment