I have this code:
var attachmentsModel = { convAttachments: ko.mapping.fromJS([]) }; $(function() { ko.applyBindings(attachmentsModel) refreshConvAttachments(); }); function refreshConvAttachments() { $.ajax({ url: '/xxxxxxx/', success: function (dataJS) {
AJAX call above returns:
[{ "title": "BillGates", "added_by": "xxx", "thumb": "urlhere", "id": 410, "link": "/link/410", "added_on": "2011-02-22T12:57:09-08:00" }, { "title": "biz-stone", "added_by": "xxx", "urlhere", "id": 411, "link": "/link/411", "added_on": "2011-02-22T12:57:53-08:00" }]
It works great. Later, the user can add an attachment and that there it will break. While it adds a new attachment to the mode and is displayed on the page, it deletes all previously loaded items in attachmentsModel.convAttachments
.
In the future, this happens:
ko.mapping.updateFromJS(attachmentsModel.convAttachments, file);
Ajax Returns:
[{ "title": "eric_schmidt", "added_by": "xxx", "thumb": "xxxxxx", "id": 417, "link": "/link/417", "added_on": "2011-02-22T13:16:45-08:00" }]
Hope this gives a clear walk if you don't let me know. Any ideas why knockoutjs kill everything when I use updateFromJS
?