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

后端 未结 13 1144
闹比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 17:59

    Two things are important for above solutions to work:

    1. When applying bindings, you need to specify scope (element) !!

    2. When clearing bindings, you must specify exactly same element used for scope.

    Code is below

    Markup

    Binding view

    var myViewModel = {
      "data" : {
        "text1" : "bla bla"
      }
    }:
    

    Javascript

    ko.applyBindings(myViewModel, document.getElementById('elt1'));
    

    Clear bindings

    ko.cleanNode(document.getElementById('elt1'));
    

提交回复
热议问题