How to clear/remove observable bindings in Knockout.js?

后端 未结 9 1955
忘了有多久
忘了有多久 2020-11-29 16:40

I\'m building functionality onto a webpage which the user can perform multiple times. Through the user\'s action, an object/model is created and applied to HTML using ko.app

9条回答
  •  佛祖请我去吃肉
    2020-11-29 17:18

    Have you thought about this:

    try {
        ko.applyBindings(PersonListViewModel);
    }
    catch (err) {
        console.log(err.message);
    }
    

    I came up with this because in Knockout, i found this code

        var alreadyBound = ko.utils.domData.get(node, boundElementDomDataKey);
        if (!sourceBindings) {
            if (alreadyBound) {
                throw Error("You cannot apply bindings multiple times to the same element.");
            }
            ko.utils.domData.set(node, boundElementDomDataKey, true);
        }
    

    So to me its not really an issue that its already bound, its that the error was not caught and dealt with...

提交回复
热议问题