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

  • Home
  • SEARCH
  • 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 7963773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:41:31+00:00 2026-06-04T05:41:31+00:00

Suppose you are making a music library app. You have one view with a

  • 0

Suppose you are making a music library app.

You have one view with a list on genres and another that shows the contents of the selected genre. When the user clicks a genre on the list, the contents in the other view should be updated accordingly.

What is the best way to do this so that there are minimal dependencies?

I have not found any other place to listen to the mouse clicks than the view that draws the individual genre. I can send an event from there, but what is the optimal way of getting that event to update the other view which draws the genre contents? Who should listen to that event, the genre content view or its collection?

EDIT: I instantiate both views from the router of the app and I did manage to get this to work by making the views aware of each other, but that’s not optimal of course.

  • 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-04T05:41:33+00:00Added an answer on June 4, 2026 at 5:41 am

    You could make a simple model to hold the application state, you don’t need anything fancy, just a bag of data that implements the usual Backbone event methods:

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

    Then the genre list view would listen for click events (as you already have) and set the current genre on the app-state model when someone changes it:

    var Genres = Backbone.View.extend({
        //...
        choose: function(ev) {
            // This would be the click handler for the genre,
            // `.html()` is just for demonstration purposes, you'd
            // probably use a data attribute in real life.
            app_state.set({genre: $(ev.target).html() });
        },
    });
    

    The view for the individual genre would listen for "change:genre" events on the app-state model and react as the genre changes:

    var Genre = Backbone.View.extend({
        initialize: function() {
            _.bindAll(this, 'change_genre');
            app_state.on('change:genre', this.change_genre);
        },
        //...
        change_genre: function() {
            // Refill the genre display...
        }
    });
    

    Demo: http://jsfiddle.net/ambiguous/mwBKm/1/

    You can make models for any data you want and models are a convenient way of working with data events in Backbone. As an added bonus, this approach makes it fairly easy to persist your application’s state: just add the usual Backbone persistence support to AppState and away you go.


    If you only need a simple event bus to push non-data events around, you can use Backbone’s Events methods to build a simple event aggregator:

    app.events = _.extend({}, Backbone.Events);
    

    Then, assuming you have a global app namespace, you can say things like this:

    app.events.on('some-event', some_function);
    

    and

    app.events.trigger('some-event', arg1, arg2, ...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a project ( myproject - a library that builds into a
Suppose I have one list: IList<int> originalList = new List<int>(); originalList.add(1); originalList.add(5); originalList.add(10); And
I am making C# windows application.In that application i have one byte array containing
Suppose I have a supertype table with many subtype tables. I'm interested in making
To give some background, I am making a UINavigationControlled-based blog type app (I suppose
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose I have a perl (or python) script that does something highly secretive; I'd
Suppose I have have made a an osX app without using Xcode. After compiling

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.