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

The Archive Base Latest Questions

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

I am building a simple to-do application in backbone. my html is: <!DOCTYPE html>

  • 0

I am building a simple to-do application in backbone.
my html is:

<!DOCTYPE html>
<html>
<head>
<title>back bone</title>
<script src="js/lib/jquery.js"></script>
<script src="js/lib/underscore.js"></script>
<script src="js/lib/backbone.js"></script>

<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<h2>Total Things Todo: <div id="no-todo"> 0 </div></h2>
<ul id="todo-list" class="unstyled">
</ul>
<div>
<button class="btn" id="add-todo"><i class="icon-plus"></i>Add Todo</button>
</div>
<script src="js/script.js"></script>

</body>
</html>

and my backbone code looks like this:

$(document).ready(function(){
    var Todo = Backbone.Model.extend({
        id: 0,
        text:null,
        completed: false
    });
    var Todos = Backbone.Collection.extend({
        model:Todo,
        initialize: function(models, options) {
            this.on("add",options.view.addTodoLi);
        }
    });
    var AppView = Backbone.View.extend({
        el: $("body"),
        initialize: function() {
            this.todos = new Todos(null,//[{id: 0,completed: false,text: "helo"},{id: 1,completed: false,text: "bye"}],
                {view: this });
        },
        events: {
            "click #add-todo": "addTodo"
        },
        addTodo: function() {
            var todo_name = prompt("What do you have to do?");
            var todo_model = new Todo({id: 0,completed: false,text: todo_name});
            this.todos.add(todo_model);
            console.log("todos",this.todos.toJSON(),
                todo_name,todo_model.toJSON());
        },
        addTodoLi: function(model){
            $("#todo-list").append("<li><div class='done-false'><input type='checkbox'/>"+model.get("text")+"</div></li>");
        }
    });
    var appview =  new AppView;
});

The problem is simple, for some reason .add function on the this.todos is not working after the first time. The add event is also triggered just once .It is as if the collection has become immutable. Have I missed something obvious?

  • 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-07T08:04:57+00:00Added an answer on June 7, 2026 at 8:04 am

    The collection simply prevents you from adding models that have the same id. If you were to add models with different ids everything should work just fine. In your case if you really don’t intend to manage the ids by yourself you could omit them upon model instantiation and have backbone generate them for you.

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

Sidebar

Related Questions

I'am building simple Ajax application (via jquery). I have strange issue. I found where
I am building a simple application that has a few buttons that when clicked
I'm building a simple application. It's a user interface to an online order system.
I'm currently building a simple application on Gjs , which should change the background-image
I'm building a simple web application in tornado.web using mongodb as the backend. 90%
# Explaining the context puts I am learning Rails, building a simple forum application.
# Explaining the context puts I am learning Rails, building a simple forum application.
Been thinking about this for hours now. Im building a simple slideshow application, where
I'm building a simple web based forum application. I want to allow users to
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET

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.