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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:42:21+00:00 2026-06-12T17:42:21+00:00

I am new in SPA’s with backbone and I am trying to develop a

  • 0

I am new in SPA’s with backbone and I am trying to develop a small app by using backbone and requireJs.

The problem I faced is that I can’t extend a view by passing a collection.

Well, this is the view with name MenuView.js

define([
'Backbone'
], function (Backbone) {
var MenuView = Backbone.View.extend({
    tagName: 'ul',
    render: function () {
        _(this.collection).each(function (item) {
            this.$el.append(new MenuListView({ model: item }).render().el);
        }, this);
        return this;
    }
});
return new MenuView;
});

and this is the router.js in which the error is appeared

define([
    'Underscore',
    'Backbone',
    'views/menu/menuView',
    'views/createNew/createNew',
    'collections/menu/menuCollection',
], function (_, Backbone, MenuView, CreateNewView,Menucollection) {

var AppRouter = Backbone.Router.extend({
    routes: {
        'index': 'index',
        'action/:Create': 'Create'
    },
    index: function () {
        CreateNewView.clear();
        //-----------  HERE IS THE PROBLEM ------------
        $('#menu').html(MenuView({ collection: Menucollection.models }).render().el);
    },
    Create: function () {
        CreateNewView.render();
    }
});

var initialize = function () {
    var appRouter = new AppRouter();
    Backbone.history.start();
    appRouter.navigate('index', { trigger: true });
};

return {
    initialize: initialize
};
});

The error message is “object is not a function”. I agreed with this since the MenuView is not a function. I tried to extend the MenuView (MenuView.extend({collection:Menucollection.models})) and the error message was “objet[object,object] has no method extend”.

I suppose that the way I am trying to do this, is far away from the correct one.

Could anyone suggest how to do this?

Thanks

  • 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-12T17:42:23+00:00Added an answer on June 12, 2026 at 5:42 pm

    Your MenuView.js returns an initialized MenuView, so you could just do:

    MenuView.collection = Menucollection
    

    Note I haven’t selected the models – I think it’s better if you don’t use the models as a replacement for your view’s collection, since it would be confusing to read the code and not have a Backbone collection as the view’s collection. You would also lose the method’s contained within the collection (e.g. fetch/update).

    If you do this, then you would need to update your loop (each is available as a method for the collection):

    this.collection.each(function (item) {
                this.$el.append(new MenuListView({ model: item }).render().el);
            }, this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new to c#. I'm trying to make a simple system where I can search
I´m starting a Proof-of-concept SPA using the new Web API and Knockout, so far
New to SharePoint. I'm trying to upload a document to SharePoint using it's CopyIntoItems
New to flash. When playing with a dummy 'tutorial' app, we saw that when
I am trying to build a little app using the Foursquare API. require 'rubygems'
New to SPA MVC4, trying to pass a session variable to LinqToEntitiesDataController from the
new on ruby and using windows xp and rails 3, i want to send
New to Node.js and Express, I am trying to understand the two seems overlapping
New programmer here, I am trying to understand and break down this code below
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I

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.