magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.4k stars 9.29k forks source link

Uncaught Error: You cannot apply bindings multiple times to the same element. when use ko.applyBindings(viewModel,province); #1934

Closed LifeAsBook closed 8 years ago

LifeAsBook commented 8 years ago
require([
    "jquery",
    "ko"
], function($,ko){

    var viewModel = {
        jdprovince: ko.observable(),
        jdprovinces: ko.observableArray()
    };
    viewModel.jdprovinceSelect = ko.dependentObservable({
        read: viewModel.jdprovince,
        write: function (jdprovince) {
            this.jdprovince(jdprovince);

        },
        owner: viewModel
    });

    $(function () {

        $.getJSON('<?php echo $block->getProvinceUrl()?>',
            null, function (response) {
                viewModel.jdprovinces(response);
            });
        var province = document.getElementById('province');

        ko.applyBindings(viewModel,province);

    });

});
guz-anton commented 8 years ago

Hi Albert, Here is jsfiddle example with your code. You can see it works. So on isolate environment code works as expected.

Probably you are trying execute it on some Magento page. And if it contains some uiComponent form then it already has binded context (that Knockout kindly says). But inside uiComponents Knockout isn't used directly.

So could you point on what page your issue occurs? What environment for code? How you add his js on the page?

LifeAsBook commented 8 years ago

thank you, i fixed http://codelea.com/X6zbDq3nDjOn/knockoutjs-single-page-application-with-pagerjs-you-cannot-apply-bindings-multiple-times-to-the-same-element.html

4DallasC commented 8 years ago

I've got this error after upgrading to Magento 2.1.0 from 2.0.7. There seems to be something left in the session that causing the problem. I launched a private window and logged in again - it went away.

rou9e commented 8 years ago

I can confirm that the purge of the browser data (session, cookies, cache, etc), login again, solved the problem for me.

sintsov commented 8 years ago

@4DallasC Thanks, it helped me