0

I am getting following erro

knockout.js:3277 Uncaught Error: You cannot apply bindings multiple times to the same element.

Below is the code

var instance = new viewModel(initialData);
                        if(typeof(document.getElementById("menueditor")) !='underfined' && document.getElementById("menueditor")[0]){
                            ko.cleanNode(document.getElementById("menueditor")[0]);
                            ko.cleanNode(document.getElementById("menueditor"));
                            //ko.utils.domData.clear(document.getElementById("menueditor"));
                        }
                        var koNode = document.getElementById('menueditor');
                        var hasDataBinding = !!ko.dataFor(koNode);
                        console.log('has data binding', hasDataBinding);
                        if (!hasDataBinding) { ko.applyBindings(instance, koNode);}
0

This is because you are trying to apply the bindings which Magento already does, within Magento 2 you should never do this.

You will need to research UI Components to see how to use Knockout within Magento 2.

A very basic component utilising Knockout looks something like this:

define([
    'ko'
], function (ko) {
    'use strict';

    return function (Component) {
        return Component.extend({
            exampleText: ko.observable('Hello')
        });
    }
});

Template:

 <div data-bind="text: exampleText"></div>

I've answered this in more detail on this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.