【发布时间】:2016-03-21 12:33:59
【问题描述】:
我正在使用一个表格,其中有一个数据表和一个用于打开模式的按钮。我需要将此按钮设置为始终启用;我尝试使用下面的代码,但没有成功。
ko.applyBindings({
editarTexto: function(data) {
alert("msg")
},
items: [{}, {}, {}]
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<fieldset data-bind="disable: true">
<table class="table">
<thead>
<tr>
<th class="col-lg-1 ">Texto</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<button type="button" class="form-control" data-bind="click: function() { $root.editarTexto($data) }, disable: false">
<span class="glyphicon glyphicon-pencil" aria-hidden="true" data-bind="disable: false">×</span>
</button>
</td>
</tr>
</tbody>
</table>
</fieldset>
谁能帮帮我?
【问题讨论】:
-
默认情况下会启用一个按钮。某些东西正在禁用它,它与
disable绑定无关。 -
除非我弄错了,“这对输入、选择和文本区域等表单元素很有用。” (knockoutjs.com/documentation/disable-binding.html) - 此列表中没有按钮元素。
-
@TSV,你确实弄错了。这些只是例子。但 Roy J 的评论似乎是正确的。代码的负责部分似乎被省略了。使按钮始终启用不需要禁用绑定。默认情况下它应该这样做。
-
@TSV 按钮是一个类似于输入的表单元素。文档中的
enable绑定示例使用了一个按钮。 knockoutjs.com/documentation/enable-binding.html -
OP,您发布的代码 works as expected, with all buttons always enabled。请更新您的问题以包含足够的代码用于minimal reproducible example。