backbone.js - Update reused BackboneJS views with jQuery -
i have secondary navigation used on views not all. include following in views use secondary navigation works without problem:
setupnavigationsecondary: => view = new app.views.users.navigationsecondary(navigation_active: ".navigation-secondary-manage") @$(".navigation-secondary").replacewith(view.render().el) you notice pass reference "navigation_active" tells secondary navigation menu item mark active. secondary navigation view has following add "active" class right menu item:
navigation_active: "" initialize: (options) -> @navigation_active = options.navigation_active setactivenavigationitem: => if @navigation_active.length $(document).ready => $(@navigation_active).parent().addclass('active') render: -> $(@el).html(@template()) @setactivenavigationitem() return the problem:
everything works fine when page first loaded directly via url in browser, i.e. correct secondary navigation item has "active" class. if started somewhere else or go elsewhere , return view secondary navigation - views on-screen updated after '$(@navigation_active).parent().addclass('active')' function executed , no menu items have "active" class.
so, how update active navigation item after secondary navigation view has loaded?
i forgot 1 important item, issue resolved now.
setactivenavigationitem: => if @navigation_active.length $(document).ready => $(@navigation_active).parent().addclass('active') should be
setactivenavigationitem: => if @navigation_active.length // line removed - don't need wait dom ready @$(@navigation_active).parent().addclass('active') // @ symbol
Comments
Post a Comment