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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:33:28+00:00 2026-05-27T20:33:28+00:00

I’m looking at the Task List example from Knockouts site and having a problem

  • 0

I’m looking at the Task List example from Knockouts site and having a problem understanding how a particular value is being set.

There is a javascript object created called Task. It has a boolean property of ‘isDone’ that is assigned through this.isDone = ko.observable(data.isDone);

My problem is that I don’t understand how the value of true or false is being passed to this property. There is no sign that it is being passed in the initial creation of the object, and the only other place in the javascript file that is using the value is this:

self.incompleteTasks = ko.computed(function() {
        return ko.utils.arrayFilter(self.tasks(), function(task) { 
            return !task.isDone() 
        });

But this is only for the totals at the bottom of the task list – and this can be completely removed and the app still will work fine (except of course you won’t have totals).

In the markup, though, the ‘isDone’ value is being used by the checkbox input:

<input type="checkbox" data-bind="checked: isDone" />

Is it possible that when the checkbox is checked, the checkbox value itself – which would be true – is passed into ‘isDone’?

Normally, I would expect that ‘isDone’ would need to already have a ‘true’ or ‘false’ value associated with it to be used in the markup, but I don’t see how the value is being assigned.

Here’s the complete code for context:

function Task(data) {
        this.title = ko.observable(data.title);
        this.isDone = ko.observable(data.isDone);


    }

    function TaskListViewModel() {
        // Data
        var self = this;
        self.tasks = ko.observableArray([]);
        self.newTaskText = ko.observable();
        self.incompleteTasks = ko.computed(function() {
            return ko.utils.arrayFilter(self.tasks(), function(task) { 
                return !task.isDone() 
            });
        });

        // Operations
        self.addTask = function() {
            self.tasks.push(new Task({ title: this.newTaskText() }));
            self.newTaskText("");

        };
        self.removeTask = function(task) { self.tasks.remove(task) };
    }

    ko.applyBindings(new TaskListViewModel());

… and here’s the markup:

<!DOCTYPE html>
    <html>
    <head>
    <title>Knockout Practice</title>

    </head>

    <body> 
        <h3>Tasks</h3>

    <form data-bind="submit: addTask">
        Add task: <input data-bind="value: newTaskText" placeholder="What needs to be done?" />
        <button type="submit">Add</button>
    </form>

    <ul data-bind="foreach: tasks, visible: tasks().length > 0">
        <li>
            <input type="checkbox" data-bind="checked: isDone" />
            <input data-bind="value: title, disable: isDone" />
            <a href="#" data-bind="click: $parent.removeTask">Delete</a>
        </li> 
    </ul>

    You have <b data-bind="text: incompleteTasks().length">&nbsp;</b> incomplete task(s)
    <span data-bind="visible: incompleteTasks().length == 0"> - it's beer time!</span>


    <script type='text/javascript' src='javascript/jquery-1.6.4.js'></script>
    <script type='text/javascript' src='javascript/jquery-tmpl.js'></script>
    <script type='text/javascript' src='javascript/knockout-2.0.0.js'></script>
    <script type='text/javascript' src='javascript/myKnockoutCode.js'></script>


    </body> 

    </html>
  • 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-27T20:33:29+00:00Added an answer on May 27, 2026 at 8:33 pm

    The checked binding determines if it is true or false loosely. This means that 0, empty string, null, false, NaN, and undefined would be considered false.

    So, it is not important for isDone to actually be initialized to false.

    When the checkbox is checked or unchecked, the checked binding will properly set it to true or false.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.