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>