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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:56:10+00:00 2026-05-23T07:56:10+00:00

I am having an issue with backbone.js and the model.save() method. I have included

  • 0

I am having an issue with backbone.js and the model.save() method. I have included a complete example below although without the three libraries needed.

I have a tag model, a tag collection model, and a model to represent some selected items in my UI, called search criteria.

I am getting a url error when attempting to save the model after I have manipulated the search criteria’s collection of tags. This example illustrates the issue.

It appears that on the final call to save in this example, backbone cannot resolve the url which is defined in the tag collection model.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
    <script src="Scripts/Libraries/jquery-1.6.1.js" type="text/javascript"></script>
    <script src="Scripts/Libraries/underscore.js" type="text/javascript"></script>
    <script src="Scripts/Libraries/backbone.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">

        $(function () {

            // Simple model for a tag. Tags have an id and a title.
            var TagModel = Backbone.Model.extend({});

            // Collection for tags.
            var TagCollection = Backbone.Collection.extend({
                model: TagModel,
                url: "tags"
            });

            // Sample model to hold a set of "selected" search criteria.
            // Includes search text and a collection of "selected" tags.
            var SearchCriteriaModel = Backbone.Model.extend({
                defaults: {
                    "searchText": "",
                    "tags": new TagCollection()
                }
            });

            // Create master tags collection.
            window.tags = new TagCollection();
            window.tags.refresh([
                { id: 1, title: "Tag A" },
                { id: 2, title: "Tag B" },
                { id: 3, title: "Tag C" }
            ]);

            // Create search criteria.
            window.searchCriteria = new SearchCriteriaModel();

            // Should be 3 tags.
            console.log("Should be 3 tags in master tags list.");
            console.log("Count = " + window.tags.size());

            // Should be 0 tags in criteria collection.
            console.log("Should be 0 selected tags.");
            console.log("Count = " + window.searchCriteria.get("tags").size());

            // Update tag title for tag 1.
            var tag = window.tags.get(1);
            tag.set({ "title": "Tag AA" });

            // Save tag.
            console.log("Try to save tag. Should attempt PUT to /tags/1. WORKS.")
            tag.save();

            // Add tag to search criteria.
            window.searchCriteria.get("tags").add(tag);

            // Should be 1 tag in criteria collection now.
            // I am not moving the tag, but rather wanting to simply add a reference to the tag to the
            // criteria collection.
            console.log("Should be 1 selected tags.");
            console.log("Count = " + window.searchCriteria.get("tags").size());

            // Should STILL be 3 tags in the master list.
            console.log("Should be 3 tags in master tags list.");
            console.log("Count = " + window.tags.size());

            // Update tag title for tag 1 again.
            var tag = window.tags.get(1);
            tag.set({ "title": "Tag AAA" });

            // Save tag.
            console.log("Try to save tag. Should attempt PUT to /tags/1. WORKS.")
            tag.save();

            // Remove tag from criteria. Simulates someone "deselecting" a tag from the search.
            window.searchCriteria.get("tags").remove(tag);

            // Should be 0 tags selected.
            console.log("Should be 0 selected tags.");
            console.log("Count = " + window.searchCriteria.get("tags").size());

            // Save tag. FAILS.
            console.log("Try to save tag. Should attempt PUT to /tags/1, but does not. Instead throws error 'A url property or function must be specified'.");
            tag.save();

        });

    </script>

</head>
<body>
    <h1>Test</h1>
    <p>Backbone test page.</p>
</body>
</html>

Any thoughts? Thanks!

UPDATED

I updated the code to help illustrate that I am not moving the tag between collections, but rather adding a reference to the tag to a second collection. Then, when I remove the tag from the second collection (not the first), Backbone cannot resolve the first collection, and then cannot get the url for saving.

I am confused as to why removing the tag from one collection would have an impact on the reference to that tag in a separate collection.

I am coming from a C# background. Maybe objects and collections work differently here.

  • 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-05-23T07:56:10+00:00Added an answer on May 23, 2026 at 7:56 am

    You’ve got two collections of tags running (one on window and one defined in your SearchCriteriaModel) and you appear to be moving a tag between the two collections

    When you execute this line of code:

    window.searchCriteria.get("tags").remove(tag);
    

    The link between that tag and a collection is lost.. the URL is determined from the collection.

    Note that if you remove the line above, your tag saves as it gets it URL from your window.tags collection.

    Ps.. good question, well asked, nicely formatted code sample demonstrating the problem.

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

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I have encountered a strange behaviour of the model validation in Backbone.js. When a
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
Having some issue with my function call please. I have a situation that I
I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping
I am having issue with git pull.I have commited my changes in local repo.
I'm building a menu options, having issue in last option, The Anchor method doesn't
I'm trying to learn Backbone.js and I seem to be having an issue with
I'm having issue assigning regex value to a string. Issue that I have is
I'm having issue with calling a method with l-value of an abstract class. The

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.