My binding:
<!-- ko if: $root.sArea() != null -->
...
<a href="#" class="btn addRemove" data-bind="click: $root.editQuestion">Edycja</a>
...
<!-- /ko -->
and the result is:
<a href="#" class="btn addRemove" data-bind="click: $root.editQuestion" disabled="disabled">Edycja</a>
On the first binding tag has no attribute disabled, but on the second and subsequent already has.
Why knockout added disabled attribute?
I found this code in solution
function EnableButtons(enable) {
if (enable)
$(".btn, .button").removeAttr("disabled", "disabled");
else
$(".btn, .button").attr("disabled", "disabled");
}
is fired twice with parameter first false, secound true, and when knokcout rebindind data he somehow "remember" disabled attribute and put this to html tag. When rebinding is call there is no disabled in html
Ok, function EnableButtons is fire before ajax call, in jquery global event
$(document).ajaxStart(function () {
...
EnableButtons(false);
});
and after ajax finish work:
$(document).ajaxComplete(function () {
...
EnableButtons(true);
});
but in ajax request on success i call rebinding data in observable.
Conclusion:
Looks like knockout have html DOM cached. If I manually enabled buttons in function ajax success then everything is ok
答案 0 :(得分:1)
Knockout没有添加禁用属性,简单明了。其他一些代码正在这样做。看起来你已经确定了一个潜在的候选人,但没有更多的代码,没有人能够帮助你。