0

I have the below view models. in view model one I also have some code that adds records to accountList. when I then try to use accountList in viewmodel two, it's always empty. shouldn't the syncWith keep those two observableArrays in sync?

ViewModel one

define(['knockout', 'text!./eligible.html', 'kendo'
    , 'toastr'
    , 'Scripts/App/models/m_accountslist'
    , 'Scripts/App/constants/cont'
    , 'postbox'
], function (ko, eligible, k, toastr, model, cont) {

    function eligibleViewModel(params) {

        var self = this;

        self.accountList = ko.observableArray().syncWith("accountList", true,false)

        return self;
    }


    return { viewModel: eligibleViewModel, template: eligible }
})

View Model Two

define(['knockout', 'text!./offermodal.html'
    , 'toastr'
    , 'Scripts/App/models/m_accountslist'
    , 'komapping'
    , 'Scripts/App/constants/cont'
    , 'postbox'], function (ko, offermodal, toastr, model, komapping,cont) {

        var offermodalViewModel = function() {
        var self = this;

        self.accountList = ko.observableArray().syncWith("accountList",true,false)

        return self;
    }
    return { viewModel: offermodalViewModel, template: offermodal }
});
user1813251
  • 329
  • 3
  • 18
  • Can you please create a fiddle, here is [one](http://fiddle.jshell.net/AnishPatelUk/8jvL1kgs/) using requirejs if it helps. Also have you tried initializing `accountList` with an array? i.e. `self.accountList = ko.observableArray([]).syncWith("accountList", true, false);` – Anish Patel Aug 04 '15 at 19:09
  • I'll try to create a fiddle for it. when I initialize the array I still don't get the sync to work – user1813251 Aug 04 '15 at 20:58
  • Hopefully you can get a fiddle that shows your issue. Here is a basic one that shows the syncing: http://jsfiddle.net/rniemeyer/rd5aLsz4/ – RP Niemeyer Aug 05 '15 at 14:05

0 Answers0