当我按下“更新”按钮时,我看到了带有正确值(真/假)的警告,但类“完成”没有得到应用。为什么视图没有更新?
<div data-bind="foreach: steps">
<div data-bind="css: {done: complete}">
<span data-bind="text: name"></span>
<button data-bind="click: updateStatus">Update</button>
</div>
</div>
var viewModel = function() {
var self = this;
self.steps = ko.observableArray();
loadTestData(testDataSteps);
function loadTestData(stepsArray) {
$.each( stepsArray, function( index, value ){
self.steps.push(new Step(value.id, value.name, value.step))
});
}
}
var Step = function (id, name, step){
var self = this;
self.id = ko.observable(id);
self.name = ko.observable(name);
self.step = ko.observable(step);
self.complete = ko.observable(false);
self.updateStatus = function () {
if(self.complete === true) {
alert("true")
self.complete = false;
}else {
alert("false")
self.complete = true;
}
};
;
1条答案
按热度按时间mrwjdhj31#
更改getter和setter方法。
第一个