2
votes

There is an issue with data binding in my html control using Knockout JS:

I have following input checkbox

<input type="checkbox" id="chbText" data-mini="true" data-bind="checked: chkAddLabel"  />

I have bind chkAddLabel property to show/hide some div using following code

 this.IsShowDiv = ko.computed(function () {
     return this.chkAddLabel();
 }

and finally the div

<div data-bind="visible: IsShowDiv"></div> 

This same code is working fine on Windows OS browsers (Chrome, IE, firefox) but not working on Nexus 7 and Nexus 5.

1
Could you put together an example in jsFiddle to duplicate the problem? - Michael Best
Make sure what release of Knockout you are using.Read in knockoutjs.com/documentation/browser-support.html and run test suit to know its support or not. If it's not supported, then create issue in there github account - Goddard
Not sure why you need a computed variable IsShowDiv which just returns the chkAddLabel value? Seems redundant - Quango

1 Answers

0
votes

You need to copy the this variable to local variable. Suppose consider it as self. We need to do this because every function having default variable this because of the parent this is override with new this.

var self = this;
self.IsShowDiv = ko.computed(function () {
 return self.chkAddLabel();
}