Knockout js checkbox count

Subscribe to a property inside of ObservableArray

<div id="colorList">
    Color List:
    <ul data-bind=" template : { name : 'simpleViewTemplate', foreach: colors }"></ul>
<div id="changedList">
    Changed List to Send to server:    ( Count: <span data-bind="text: changedColors().length"></span> )
    <ul data-bind=" template : { name : 'changedColorsTemplate', foreach: changedColors }"></ul>

<script type="text/x-jquery-tmpl" id="simpleViewTemplate">
        <input type="checkbox" data-bind="checked: IsChecked"/> <font data-bind="text: Name, attr : { color: Name }"></font>
<script type="text/x-jquery-tmpl" id="changedColorsTemplate">
        <b><span data-bind="text: Id"/></b>
var color = function (id, name, isChecked) {
    this.Id = ko.observable(id);
    this.Name = ko.observable(name);
    this.IsChecked = ko.observable(isChecked);
    this.IsCheckedOriginal = ko.utils.unwrapObservable(this.IsChecked);

    // Subscribe when checked changes and push or remove items
    this.IsChecked.subscribe(function () {
        if (this.IsChecked() != this.IsCheckedOriginal) {
        } else {

var viewModel = {
    name: ko.observable(),
    colors: ko.observableArray([
    new color(101, "Red", false),
    new color(102, "Blue", false),
    new color(103, "Green", false),
    new color(104, "Violet", false)]),
    changedColors: ko.observableArray([]) // holds changed items - delta between all colors and unchecked colors

Knockout js checkbox count Knockout js checkbox count Reviewed by Bhaumik Patel on 8:27 PM Rating: 5