KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element

后端 未结 13 1164
闹比i
闹比i 2020-12-04 17:38

I\'ve just upgraded to 2.3.0 and now I\'m getting the error

You cannot apply bindings multiple times to the same element.

that

13条回答
  •  佛祖请我去吃肉
    2020-12-04 18:06

    In my case, I was adding to a non existing element, or, I was adding bindings to an element that maybe exists, but it's parent did not. Similar to this:

    var segDiv =  $("#segments"); //did not exist, wrong id
    var theDiv = segDiv.html("
    "); ko.applyBindings(someVM, theDiv);

    As far as I can tell, this error seems a bit overloaded in the sense that it will fire on a lot of different errors that can happen with the element, like it not existing. As such, the error description can be highly deceptive. It should have probably read:

    "Failure to bind bindings to element. Possible reasons include: multiple binding attempts, element not existing, element not in DOM hierarchy, quirks in browsers, etc"

提交回复
热议问题