简体   繁体   English

复选框中的剔除数据绑定不适用于Android(4.2)

[英]Knockout data-bind in checkbox not working on android (4.2)

There is an issue with data binding in my html control using Knockout JS: 使用Knockout JS的html控件中的数据绑定存在问题:

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 我已绑定chkAddLabel属性以使用以下代码显示/隐藏一些div

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

and finally the div 最后是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. 相同的代码在Windows操作系统浏览器(Chrome,IE,firefox)上可以正常工作,但在Nexus 7和Nexus 5上则无法工作。

You need to copy the this variable to local variable. 您需要this变量复制到本地变量。 Suppose consider it as self . 假设将其视为self We need to do this because every function having default variable this because of the parent this is override with new this . 我们需要这样做,因为每个函数由于父this都具有默认变量this因此会被new this覆盖。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM