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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:13:10+00:00 2026-06-08T06:13:10+00:00

I have a backbone model like so define([ ‘underscore’, ‘backbone’ ],function( _,Backbone) { var

  • 0

I have a backbone model like so

define([
'underscore',
'backbone'
],function( _,Backbone) {
    var Task =  Backbone.Model.extend({
        //api url
        url:'',

        methodToURL: {
        'read': './api/tasks/index',
        'create': './api/tasks/task',
        'update': './api/tasks/task',
        'delete': './api/tasks/task'
        },
        sync: function(method, model, options) {
            options = options || {};
            options.url = this.methodToURL[method.toLowerCase()];

            Backbone.sync(method, model, options);
        }
    });
    return Task;
});

And a collection

define(['underscore','backbone','models/task'],function( _,Backbone,Task) {
    var TaskCollection = Backbone.Collection.extend({
        //Model
        model:Task,
        //api url
        url:'',

        methodToURL: {
        'read': './api/tasks/index',
        'create': './api/tasks/task',
        'update': './api/tasks/task',
        'delete': './api/tasks/task'
        },

        sync: function(method, model, options) {
            options = options || {};
            options.url = this.methodToURL[method.toLowerCase()];

            Backbone.sync(method, model, options);
        },
        //construct
        initialize: function() {
            this.sort_key = 'end';
            this._model = new Task();
            this.fetch();
        },

        comparator: function(a,b) {
            a = a.get(this.sort_key);
            b = b.get(this.sort_key);
            return a > b ?  1
                 : a < b ? -1
                 :          0;
        },

        mark_complete: function(task_id) {
            var task_status = 0;
                    console.log(this.model);
            this.model.save({id:task_id,task_status:task_status});
        },

        mark_incomplete: function(task_id) {
            var task_status = 1;
                    console.log(this.model);
            this.model.save({id:task_id,task_status:task_status});
        },

        sort_by_status: function() {
            this.sort_key = 'task_status';
            this.sort();
        },

        sort_by_task_tag: function() {
            this.sort_key = 'task_group';
            this.sort();
        }
    });
    return TaskCollection;
});

When i the mark_complete method runs the model is logged to the console, but it logs this
“function (){ parent.apply(this, arguments); } ” and says “function (){ parent.apply(this, arguments); } has no method 'save'“;
Am guessing the model is supposed to be instantiated so the collection can have access it to its methods, so what is wrong?

  • 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-08T06:13:11+00:00Added an answer on June 8, 2026 at 6:13 am

    The model property is just a constructor that Collection uses when you add a model to the collection. It is intended to make your life easier when you try to input data to the collection. Instead of always calling the constructor when adding a Task model to TaskCollection, you’d just input a JavaScript object and it will do the same thing.

    So this is how your code would look like when you would want to insert a model without setting the model property to your TaskCollection

    taskCollection.add(new Task({ 
        name: "Get Milk",
        description: "We're out of milk. There's a sale going on at the local supermarket." 
    }));
    
    // If you wanted to just input just the JSON object without calling the
    // constructor, then you can't.
    

    And this is how your code would look like if you had set the model property

    taskCollection.add({
        name: "Get Milk",
        description: "We're out of milk. There's a sale going on at the local supermarket." 
    });
    

    As you can see, you don’t need to call the Task constructor; the instance of TaskCollection will call it for you.

    And this is why instances of TaskCollection will only have the model property set to the actual constructor of Task, not an initialized version.

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

Sidebar

Related Questions

I have the following situation: var Task = Backbone.Model.extend({ initialize: function() { }, save:
I have this model var Item = Backbone.Model.extend({ url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials' }); var onSuccess
I have a model which looks like this: //myModel.js define([], function () { var
I have two backbone models, loaded from server: var Model = Backbone.Model.extend({}); var SubModel
If i have this model: var myParentModel = Backbone.Model.extend({ defaults:{ parent1: null, parent2: null}
I have a simple demo app like this Friend = Backbone.Model.extend name:null Friends =
usually a requirejs module looks like: define('ModuleName', ['jquery', 'underscore', 'backbone'], function($, _, Backbone){ });
I have created a new backbone.js widget model which I hope to extend: var
I have noticed that when multiple attributes of a Backbone model are set like
Basically, I'm trying to do something like this: Person = Backbone.Model.extend({ validate: { ...

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.