我已经定义了类似self.loadAffected = function(){ko.observable(true);}
并尝试在其他功能上打印
self.loadAffectedChanged = function() {
// clear "Road Blocked" when Load Affected is selected
**alert(self.loadAffected());**
if (self.loadAffected === false)
self.groupable(false);
else
// clear "Groupable" when Load Affected is cleared
self.roadBlocked(false);
};
通过类似HTML的方法调用上述功能
<input type="checkbox" data-bind="jqmChecked: loadAffected, click: loadAffectedChanged"
name="load_affected" id="load_affected"/>
有人可以解决这个问题吗?
答案 0 :(得分:0)
self.loadAffected()
将始终为您提供undefined
,因为它只是一个不返回任何内容的函数。我不确定custom binding jqmChecked
的用途,但与该问题无关。
您应该将代码更改为:
self.loadAffected = ko.observable(true); // now loadAffected is an observable
self.loadAffectedChanged = function() {
// you need to add the parentheses here to read the value of loadAffected observable
if (self.loadAffected() === false)
self.groupable(false);
else
// clear "Groupable" when Load Affected is cleared
self.roadBlocked(false);
};