Using updateFromJS is replacing values when it should be adding them

前端 未结 2 1218
我在风中等你
我在风中等你 2021-01-26 04:42

I have this code:

var attachmentsModel = {
    convAttachments: ko.mapping.fromJS([])
};

$(function() {
    ko.applyBindings(attachmentsModel)
    refreshConvAt         


        
相关标签:
2条回答
  • 2021-01-26 05:14

    ko.mapping.updateFromJS() expects that you are receiving the complete list of items that was originally prepared with ko.mapping.fromJS(). Any items that are missing from the original are considered to be deleted and any new items in the updates are considered additions. So, currently the mapping plugin will not allow you to do incremental updates in this way.

    If you are doing incremental updates, your best bet would be to locate the items that you need to update and either replace them completely or replace individual observables on each item.

    0 讨论(0)
  • 2021-01-26 05:14

    you could always try using

    $.extend(attachmentsModel.convAttachments,ko.mapping.fromJS(dataJS));
    

    Although i am not quite sure if that will update all the bindings properly, you might have to reply the binding by calling

    ko.applyBindings(attachmentsModel)
    
    0 讨论(0)
提交回复
热议问题