javascript - Backbone model change and view render update -
I have an express app with back end session, and in front I have a BABON + requirement I have my problem The session is near the model, and the change event that triggers the render method on ideas.
Such:
- The app has a home view, so the session is a listener for the "change" event of the model, and runs the "render" method.
- Users with no credentials go from home to a public page, say / talk about /
- There, user login (user / password) that entered the entrance.
- Due to the listener in item 1, the container element is updated with the new home content, but the user is still about /. So, the question is: How do I avoid this bad behavior so that only the events listen when the right path is active?
One code example:
"harsh use"; Var session mode = backbone.model. Extension ({}); Var sessionmodel = new session model (); Var Homeview = Backbone View. Expansion ({initialize: function () {this.listenTo (SessionModel, "change", this.render);}, render: function () {// main container element update}}); Var apprauter = backbone.routor.andand ({"": "home", "about": "about"}); Var appraiser = new apparatus (); AppRouter.on ("route", function () {sessionModel.fetch (); // update session model on each path change}}; AppRouter.on ("route: home", function () {var homeview = new homeview ( ); HomeviewRedder ();});
Instead of listening, you can listen to a specific feature. / P>
this.bind ("change: someExpecificThing", doEspecificThing)
Comments
Post a Comment