Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8066565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:03:12+00:00 2026-06-05T12:03:12+00:00

I have a fairly large Backbone app with Menu/Submenu being a separate view. Inside

  • 0

I have a fairly large Backbone app with Menu/Submenu being a separate view. Inside the menu view i have the logic to handle click event on li and highlight that. However i am stuck on how to highlight a particular li when i navigate to another view from within the application (using the router, for eg.)

Options available:

  1. From each of the Views render(), access the menu div and highlight the required li
  2. Use Event mechanism and from each of the views render() trigger an event like 'CustomerUpdate::render'.

I feel 2] is the right way to do it. But i am open to suggestions.

What techniques do you follow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:03:13+00:00Added an answer on June 5, 2026 at 12:03 pm

    (1) is a bit nasty, that leaks the menu’s internal state and structure all over the place. You’ll end up with your main views tightly coupled with your menu, that leads to a small ball of mud and small balls of mud always grow into big balls of mud.

    I think (2) is on the right track but I’d pull it apart a little more. The current view is part of your application’s state and switching views through a router is a change in your application’s state. What do we use in Backbone to track state and state changes? We use models and "change" events. If you have a dedicated global model for your application’s state:

    AppState  = Backbone.Model.extend({});
    app_state = new AppState;
    

    Then the view that manages the menu could bind to changes in app_state:

    initialize: function() {
        _.bindAll(this, 'change_current_view');
        app_state.on('change:current_view', this.change_current_view);
    }
    

    and the event handler could deal with the <li>s:

    change_current_view: function() {
        this.$('li').removeClass('current');
        // This selector is, of course, just for illustration
        this.$('#' + app_state.get('current_view')).addClass('current');
    }
    

    Then your router can swap the view and app_state.set({ current_view: '...'}) to trigger the auxiliary actions. You could even have something, such as an application level view, that listens for "change:current_view" and let that listener deal with swapping the view; that would simplify your router. Here’s a quick demo to help illustrate what I’m talking about:

    http://jsfiddle.net/ambiguous/fr8sG/

    This “application state model” approach is quite useful in general; you can easily add more bits of state to the app-model, set up preferences editors, etc. You’ll also get persistence and application initialization almost for free.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have fairly large Latex document with a lot of TikZ figures inside. I
So, I have a fairly typical app with UITableViewController 's inside of an UINavigationController
I have a fairly large, three level deep, menu consisting of nested lists like
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
I have a fairly large js lightbox gallery and an hasty user can click
I have a fairly large windows mobile app (written in NETCF 3.5). Those in
I have an android app that is getting fairly large and complex now, and
I have a fairly large CRUD winform app that is set up to display
I have a fairly large C++ application (on Windows, no other platforms planned), which
I have a fairly large Excel file. In this file there is a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.