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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:50:46+00:00 2026-06-10T15:50:46+00:00

A Backbone Collection and some Views are created in the return function of click()

  • 0

A Backbone Collection and some Views are created in the return function of click() as shown in the code snippet below.

Problem: How can I access backbone.js objects like the Collection productList using the Javascript console? this.productList does not return anything, so I believe productList is not a direct child of the window object. How then should I create productList collection?

JS Code

$('#submit_btn').click(function() {
        console.log('do something');
    }, function() {

        this.productList = new ProductCollection();
        var self = this;
        self.productListView = new ProductListView({ collection: self.productList });
        this.productList.fetch({
            data: {gender: 'men'},
            processData: true
        });

    });
});
  • 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-10T15:50:47+00:00Added an answer on June 10, 2026 at 3:50 pm

    Right now in this case you cannot can everything is in an anonymous function so you cant access it after the function has executed. This is anyways not the right way to do things, or not the backbone way.

    This is how i generally do stuff,
    create a central namespace like app and then create all the models, collections and views to that namespace as

    window.App = {
       //model
       Curve : {},
       //collection
       CurveManager : {},
       //view
       Views : {},
       //controller
       Controller : {}
    }
    

    plus i think that you should take care of the click event from a backbone view itself then it would be comparatively easier for you to visualize things. For example in http://backbonejs.org/docs/todos.html take a look at the AppView events. that should make things much more clearer.

    here is that part of the code

    var AppView = Backbone.View.extend({
        el: $("#todoapp"),
        statsTemplate: _.template($('#stats-template').html()),
        events: {
          "keypress #new-todo":  "createOnEnter",
          "click #clear-completed": "clearCompleted",
          "click #toggle-all": "toggleAllComplete"
        },
    
        .
        . // more code in between
        .
    
        createOnEnter: function(e) {
          if (e.keyCode != 13) return;
          if (!this.input.val()) return;
    
          Todos.create({title: this.input.val()});
          this.input.val('');
        },
    

    I generally look at other peoples code on github and try to learn how they do things and how things should be done, i suggest you do the same. It helps a lot 🙂 The todoapp annotated source is really clean and pretty easy to understand.

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

Sidebar

Related Questions

I can successfully do this: App.SomeCollection = Backbone.Collection.extend({ comparator: function( collection ){ return( collection.get(
I'm beginning with backbone.js Going through some tutorials, like the one shown below. I
I'm having issues loading a collection of Backbone Views with RequireJS - as they
As in the backbone-todolist example,I have a collection of elements. I made 2 views,
I'm having a problem that I really can't comprehend… I'm not sure if backbone
With Backbone.js I've got a collection set up with a comparator function. It's nicely
I've a Backbone Collection initialized but calling invoke on collection doesn't work. For some
I have some code like this: var User = function () { _.bindAll(this) this.UserList
I've just started using Backbone.js. I want to create a Collection and add some
I've seen backbone views (or models, collections etc), declared like this var SomeView =

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.