0

我正在尝试使用 knockout.js 的可见绑定在选择的值之间进行切换,并取决于选择的值。当值为 = '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> 
4

1 回答 1

1

如果 term 是可观察的,您需要这样访问它:

visible: $data.term() != 5
visible: $data.term() == 5
于 2013-03-22T11:40:46.270 回答