【发布时间】:2016-02-25 21:34:33
【问题描述】:
我想让以下输入仅在选择 database 属性时才可见(在 Bootstrap 更改事件中)。在 Knockout JS 中是否有一个优雅而有效的解决方案可以在 HTML 中执行此操作,如果没有,那么 JavaScript 方式是什么?
<select id="db" class="form-control" data-bind="value: database, valueUpdate: 'change'">
<option disabled selected> -- select an option -- </option>
<option>MySQL database format</option>
<option>PostgreSQL database format</option>
<option>Other format</option>
</select>
<label>Address :</label>
<input type="text" class="form-control" id="address" data-bind="visible: database">
<label>Port :</label>
<input type="text" class="form-control" id="port">
我正在考虑使用data-bind="visible: typeof database != 'undefined'" 之类的东西,但尝试访问database 时会抛出Uncaught ReferenceError: database is not defined。使用 jQuery 的方法也不起作用。
【问题讨论】:
标签: javascript knockout.js data-binding durandal durandal-2.0