1

I'm using knockout and I have 2 radio buttons, when a particular one is selected I need a textbox to be enabled and disabled if the other option is selected. 我似乎无法让这个工作。这是我到目前为止所拥有的:IssercentageBased 是我的视图模型上的布尔值,我已将其设置为可观察的。有任何想法吗?

<input type="radio" name="IsPercentageBased" value="true" data-bind="checked: IsPercentageBased"/>
            <span>Percentage</span>
            <input type="radio" name="IsPercentageBased" value="false" data-bind="checked: IsPercentageBased"/>
            <span>Value</span>

 @Html.TextBox("Value", "", new
                {
                    type = "text",
                    data_bind = "value: Value, valueUpdate: 'afterkeydown', disable: IsPercentageBased"
                })
4

1 回答 1

2

将文本框的 data-bind 属性更新为:

data_bind = "value: Value, valueUpdate: 'afterkeydown', disable: IsPercentageBased() == 'true'"

Checked绑定设置为Value属性的可观察值,stringbool.

这是工作小提琴:http: //jsfiddle.net/vyshniakov/wDRuG/

于 2012-11-06T11:46:51.330 回答