【问题标题】:Visible binding not working in combination with radio buttons可见绑定不能与单选按钮结合使用
【发布时间】:2013-05-13 00:43:54
【问题描述】:

我希望“EnterTemplate”div 基于单选按钮有条件地可用。我在最底部添加了text data-bind 以进行测试,它根据单选按钮的值向我返回“true”或“false”值。我正在尝试分配 visible 绑定此值,但没有任何反应。有什么建议吗?

<div><h4>Select Instrument Template:</h4></div>
<div id="ChooseModel">
    <strong>Would you like to manually insert number?</strong><br />
    <input type="radio" name="ChooseModel" value="True" data-bind="checked: RadioOption"/>@Resx.Yes
    <input type="radio" name="ChooseModel" value="False" data-bind="checked: RadioOption"/>@Resx.No
</div>
<div id="EnterTemplate" data-bind="visible: RadioOption">
    <div><strong>Model Number: </strong></div>
    <div><input data-bind="value: ModelNumberString" /></div>
    <div><strong>Manufacturer: </strong></div>
    <div><input data-bind="value: ManufacturerString" /></div>

    <div>Model Number: <strong data-bind="text: ModelNumberString"></strong></div>
    <div>Checked: <strong data-bind="text: RadioOption"></strong></div>
</div>

【问题讨论】:

标签: html knockout.js


【解决方案1】:

它总是可见的,因为任何非空字符串总是真实的,你应该这样做:

data-bind="visible: RadioOption() === 'True'"

或者有其他布尔属性。

【讨论】:

  • 你在寻找“真相”
猜你喜欢
  • 2013-06-07
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 2019-08-10
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 2016-01-18
相关资源
最近更新 更多