我正在尝试使用knockout.js的可见绑定来切换和取决于select的值。当值为''5'时,我想切换元素,任何人都可以解释我哪里出错了吗?我也是在foreach中做这个,也许我对比较的变量范围有误?感谢
<table border="1" cellpadding="4" cellspacing="0" id="terms_table">
<thead>
<tr class="term_row">
<th><div align="center">Percentage</div></th>
<th><div align="center">Payment Terms</div></th>
<th><div align="center">Stage</div></th>
<th><div align="center">Delete</div></th>
</tr>
</thead>
<tbody data-bind="foreach: terms" >
<tr class='spec_row'>
<td class='center'><input size='5' data-bind="value : percentage" /></td>
<td class='center'>
<select data-bind='visible: $data.term != 5, options: $parent.termOptions,
value: $data.term, optionsValue: "id", optionsText: "option"'></select>
<input data-bind='value: other, visible: $data.term == 5 ' />
</td>
<td class='center'><input size='60' data-bind="value : stage" /></td>
<td class='center' valign='middle'>
<input type='hidden' data-bind="value : id" />
<input type='hidden' data-bind="value : rank" />
<img width='12' height='12' class='move' src='/images/cursor_drag_arrow.png' />
<img width='12' height='12' class='psuedo_link' src='/images/deleteCross.gif'
data-bind='click: $parent.removeTerm' /></td>
</tr>
</tbody>
</table>
</div>
答案 0 :(得分:1)
如果term是可观察的,则需要按以下方式访问:
visible: $data.term() != 5
visible: $data.term() == 5