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 8184963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:40:55+00:00 2026-06-07T01:40:55+00:00

I’m starting with Backbone and stumbled upon a question recently. The sample application I’m

  • 0

I’m starting with Backbone and stumbled upon a question recently. The sample application I’m working on is some kind of playlist. I have a model ‘song’ and a collection ‘Playlist’, containing several songs.

The data of the Playlist-collection should be available in multiple views. So my idea is to have global application-variables, and one of these variables could be the Playlist-collection.

This way, I can fetch the songs with the initialization of the app, and access the data in every view of the app.

Below is what I’m doing currently

  define(
        [
            'jQuery',
            'Underscore',
            'Backbone',
            'collections/songlist'
        ],

        function ($, _, Backbone, SonglistCollection)
        {
            var PlaylistView = Backbone.View.extend({

                // properties
                el: '#playlist',
                collection: new SonglistCollection(),

                /**
                 * Initialize
                 */
                initialize: function()
                {
                    // load songs
                    this.collection.on( 'reset' , this.render, this );
                    this.collection.fetch();
                },

                /**
                * Render
                */
                render: function()
                {
                    // loop through the collection and update the view
                },

                ...
            );
        }
);

And this is my collection

define(
    [
        'Underscore',
        'Backbone',
        'models/song'
    ],

    function (_, Backbone, songModel)
    {

        var songList = Backbone.Collection.extend({

            model: songModel,
            url: 'song'
        });

        return songList;
    }
);

As you can see, I have to make a new instance of the collection and re-fetch the data for every view where I want to use the data of the Playlist-collection.

Because I’m using require.js, I’m a bit lost about how to create global variables. The way I like to do it is eg. make MyApp.collections.Playlist, but I have no idea how to realize this with AMD (require.js).

Some resources I’ve already found, but I’m still lost / confused / …

  • Share resources across different amd modules
  • http://www.alexrothenberg.com/2011/02/11/backbone.js-makes-building-javascript-applications-fun.html

Thanks a lot in advance!

  • 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-07T01:40:56+00:00Added an answer on June 7, 2026 at 1:40 am

    If you have a file namespace.js: (in your case myapp.js)

    define([
      // Libraries.
      "jquery",
      "lodash",
      "backbone",
    
      // Plugins.
      "plugins/backbone.layoutmanager"
    ],
    
    function($, _, Backbone) {
    
      // Provide a global location to place configuration settings
      var namespace;
    
      // ...
      return namespace;
    });
    

    Then in your modules / Collections, just import that file, the same way that you will do with other library:

    define([
      "namespace",
    
      // Libs
      "backbone"
    ],
    
    function(namespace, Backbone) {
    
    
      // This will fetch the tutorial template and render it.
      var Playlist = namespace.collections.Playlist = Backbone.View.extend({
              //...
      });
    
      // Required, return the module for AMD compliance
      return Playlist;
    
    });
    

    The same way, you can define a router. And then in a separate main.js file, is where the app is initialized (using require() instead of define() )

    Credit: this way of structuring the app I found it in the tbranyen BB boilerplate:
    https://github.com/tbranyen/backbone-boilerplate/tree/master/app/tree

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.