简体   繁体   English

根据在Knockout.JS中选择的下拉值设置文本框的可见性

[英]Setting visibility of the Text Box based on the dropdown value selected in Knockout.JS

I have the following dropdown 我有以下下拉菜单

<select class="sf-dropdown" data-bind="options: Statuses, optionsText: 'Description', value: SelectedStatus, valueAllowUnset: false"></select>

And if the dropdown value selected is 'Not Completed' (which has status value of 0), I want the textbox to appear. 而且,如果选择的下拉值是“未完成”(状态值为0),我希望显示该文本框。

I have my textbox as 我的文本框为

<input type="text" id="txtTaskReason" style="width: 40%" data-bind="with: SelectedStatus, visible: SelectedStatus()==='Not Completed', value: Reason" />

However it doesn't seem to work. 但是,它似乎不起作用。 Any ideas on what I am doing wrong? 关于我在做什么错的任何想法吗? Thanks 谢谢

It looks like the SelectedStatus value is an object so if you change to 看起来SelectedStatus值是一个对象,因此如果更改为

visible: SelectedStatus() && SelectedStatus().Description ==='Not Completed'

it might work. 它可能会起作用。

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

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