淘汰赛本身为<a>

时间:2015-04-28 07:26:44

标签: knockout.js

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:

  1. Before ajax call all buttons are disabled=""disabled",
  2. on ajax success is rebinding and buttons state are still disabld.
  3. At the end when ajax is competed buttons state is changed to "enabled"
  4. And now when ja call rebindind data but i didn't call ajax my buttons change status to disabled, why?

Looks like knockout have html DOM cached. If I manually enabled buttons in function ajax success then everything is ok

1 个答案:

答案 0 :(得分:1)

Knockout没有添加禁用属性,简单明了。其他一些代码正在这样做。看起来你已经确定了一个潜在的候选人,但没有更多的代码,没有人能够帮助你。