如何使用带有单选按钮可观察参数的可见绑定?

Dav*_*Fox 4 javascript data-binding knockout.js

此页面呈现时选择了正确的单选按钮,但是当选择"sendemail"或"sms"单选按钮值时,应显示其他输入,对吗?

$(function () {
    var rbViewModel = {
        qrType: ko.observable('plaintext')
    };
    ko.applyBindings(rbViewModel);
});
Run Code Online (Sandbox Code Playgroud)

然后我的单选按钮

<input type="radio" name="txtType" value="plaintext" data-bind="checked: qrType" />Plaintext
<input type="radio" name="txtType" value="sendemail" data-bind="checked: qrType" />Send E-mail
<input type="radio" name="txtType" value="sms" data-bind="checked: qrType" />SMS
Run Code Online (Sandbox Code Playgroud)

我的意见:

<div data-bind="visible: qrType == 'sendemail'"><input type="text" id="txtEmailSubject" placeholder="E-mail subject" /></div>
<div data-bind="visible: qrType == 'sendemail'"><input type="text" id="txtEmailBody" placeholder="E-mail body" /></div>
<div data-bind="visible: qrType == 'sms'"><input type="text" id="txtSmsMsg" placeholder="SMS body" /></div>
Run Code Online (Sandbox Code Playgroud)

div元素上的属性有问题吗?我认为函数可以在每个KnockoutJS 文档的可见绑定中使用,如下所示:

data-bind="visible: qrType=='sendemail'"
Run Code Online (Sandbox Code Playgroud)

RP *_*yer 7

在data-bind属性中的表达式中使用observable时,需要使用()引用它.

他们需要看起来像: visible: qrType() === 'sendemail'