Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

Knockout JS - you cannot apply bindings multiple times to the same element - MVC

$
0
0

I am new to knockout js and dont understand why i am getting this error.

I have a view in .net mvc that when a button is clicked uses jquery to query the database with ajax and then returns data, then i pass it to knockout to render, when you click on the button it opens a modal window and displays the data fine, but it only does it once, every second time and time after it displays the multiple elements error.

Any ideas?

 var ViewModel = function (docs) {

  this.docs = ko.observable(docs);

};

$('.js--click').click(function () {

    var id = $(this).data('id');

        $.post("GetData", { id: id })
           .done(function (data) {

             ko.applyBindings(new ViewModel(data.docs));
    });
});


<div data-bind="if: docs()">
<span data-bind="text: docs></span>
</div>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>