I have a list of attachments on a page that is created by calling jQuery $.ajax and JS knockout.
My HTML looks like (this disappears):
<tbody data-bind="foreach: attachments"> <tr> <td data-bind="text: Filename" /> </tr> </tbody>
I have a function that gets a list of attachments that is returned as a JSON response:
$(function () { getFormAttachments(); }); function getAttachments() { var request = $.ajax({ type: "GET", datatype: "json", url: "/Attachment/GetAttachments" }); request.done(function (response) { ko.applyBindings(new vm(response)); }); }
My model looks like this:
function vm(response) { this.attachments = ko.observableArray(response); };
There is an update button that you can use to update this list, because added / deleted time attachments can be added / removed:
$(function () { $("#refresh").on("click", getAttachments); });
The initial rendering of the attachment list is fine, however, when I call getAttachments again using the refresh button, click on the list added to (in fact, each item is duplicated several times).
I created jsFiddle to demonstrate this problem here:
http://jsfiddle.net/CpdbJ/137
What am I doing wrong?
Kev
source share