【发布时间】:2021-01-13 01:13:43
【问题描述】:
当检查“ setAlarmValues”时,我正在尝试为“ SetoutputCurrentPpplowValue”和“ SetoutputcurrentPpphighValue”设置为true。对于这个问题,我有以下代码:
这些字段在页面加载时被禁用,但当“SetAlarmValues”被选中时,它们保持禁用状态。我不确定为什么。请帮忙!
<!-- ko if: $root.regData -->
<div class="row">
<div class="col-md-2">
<label for="SetAlarmValues" class="control-label">@MSL.Core.Resource.Models.Well.SetAlarmValues:</label>
<input type="checkbox" data-bind="checked: $root.regData().setAlarmValues" class="large-check registration" id="SetAlarmValuesCheck" title="@MSL.Core.Resource.Models.Well.SetAlarmValues" />
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-3">
<label for="SetOutputCurrentPP" class="control-label">Set Output Current PP:</label>
</div>
</div>
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-5 form-inline">
<label for="SetOutputCurrentPPLowValue" class="control-label">@MSL.Core.Resource.Models.Well.OutputCurrentPPLowValue: </label>
<input type="checkbox" data-bind="checked: $root.regData().setOutputCurrentPPLowValue, enable: $root.regData().setAlarmValues()" class="large-check registration" id="SetOutputCurrentPPLowValue" title="@MSL.Core.Resource.Models.Well.SetOutputCurrentPPLowValue" />
<input type="text" id="OutputCurrentPPLowValue" data-bind="value: $root.regData().outputCurrentPPLowValue, enable: $root.regData().setOutputCurrentPPLowValue" class="form-control" maxlength="30" />
</div>
</div>
<br />
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-5 form-inline">
<label for="SetOutputCurrentPPHighValue" class="control-label">@MSL.Core.Resource.Models.Well.OutputCurrentPPHighValue:</label>
<input type="checkbox" data-bind="checked: $root.regData().setOutputCurrentPPHighValue, enable: $root.regData().setAlarmValues()" class="large-check registration" id="SetOutputCurrentPPHighValue" title="@MSL.Core.Resource.Models.Well.SetOutputCurrentPPHighValue" />
<input type="text" id="OutputCurrentPPHighValue" data-bind="value: $root.regData().outputCurrentPPHighValue, enable: $root.regData().setOutputCurrentPPHighValue" class="form-control" maxlength="30" />
</div>
</div>
</div>
<!-- /ko -->
这是脚本:
function Registration() {
var self = this;
//Alarms
self.setAlarmValues = ko.observable(false);
self.setOutputCurrentPPLowValue = ko.observable(false);
self.setOutputCurrentPPHighValue = ko.observable(false);
self.outputCurrentPPLowValue = ko.observable("");
self.outputCurrentPPHighValue = ko.observable("");
}
var registerVM = function (countryListJSON, companyListJSON, wellStatusListJSON, territoryListJSON) {
self = this;
self.validation = ko.observableArray([]);
self.savingData = ko.observable(false);
self.regData = ko.observable(new Registration());
}
【问题讨论】:
-
使用
with绑定去掉多余的代码。代码看起来不错,如果你能提供一个工作示例(小提琴)很乐意提供帮助。 -
@supercool 我已经对上面的代码做了一些修改,它正在工作。但在 Visual Studio 中并非如此。很烦人。问题是
with将隐藏我所知道的所有内容,但我希望它显示但仅在选中复选框时启用。这是小提琴:link -
@supercool 我尝试使用
with绑定,它再次适用于小提琴,但不适用于我的!我不知道出了什么问题。这是此绑定的小提琴:link -
VS 与问题无关。仍然
with未正确使用请参阅此 jsfiddle.net/8vwqzjnh 。with创建了孩子们可以参考的新上下文。 -
@supercool 也没有用。所以我尝试使用 iCheck。这是小提琴:link 但由于某种原因,这是唯一不能在小提琴中工作但它实际上在我的本地工作的代码。
标签: checkbox knockout.js isenabled