SteveSanderson/knockout — Issue #227: Subsequent post backs result in DOM explosion
Author: BedfordPeterson
Created: 2011-12-12 19:51:05+00:00
State: open

On the initial page load, I load the following objects into a collection of foreach
elements and everything is perfect, but subsequent loads or refreshes result in the last
repeating multiple times (usually four). If I remove it, then it repeats the next element up. Any help would be greatly appreciated.

Here is the view model:

var businessUnit = function (id, name, deviceCount, licenseCount, siteEvents, failedArchives) {
this.ID = new ko.observable(id);
this.Checked = new ko.observable(false);
this.Name = new ko.observable(name);
this.DeviceCount = new ko.observable(deviceCount);
this.LicenseCount = new ko.observable(licenseCount);
this.SiteEvents = new ko.observable(siteEvents);
this.FailedArchives = new ko.observable(failedArchives);
}

var organization = function (sortByName) {
this.BusinessUnits = new ko.observableArray([]);
this.SortByName = new ko.observable(sortByName);
this.CheckCount = new ko.dependentObservable(function () {
var count = 0;
ko.utils.arrayForEach(this.BusinessUnits(), function (bu) {
var value = Boolean(bu.Checked());
if (value == true) {
count += 1;
}
});
return count;
}, this);

this.FirstId = new ko.dependentObservable(function () {
var id = "";
ko.utils.arrayForEach(this.BusinessUnits(), function (bu) {
var value = Boolean(bu.Checked());
if (value == true) {
if (id == "") {
id = bu.ID();
}
}
});
return id;
}, this);

this.IsSortByColumn = new ko.dependentObservable(function (title) {
return title == this.SortByName();
}, this);

}

Here is the HTML: