user1813251
user1813251

Reputation: 339

knockout-postbox and knockout components can you syncWith observable arrays?

I have two components that I want to sync an observable array between them. It works find with an observable, but with an array it never syncs. Can you syncWith an observable array?

If I convert the array to string and then sync the observable it passes, but then I have to reconstruct the observable array on the other vm. Can it be done with just a syncWith?

vm1

  self.offers = ko.observableArray([]).syncWith("offersLink");


            var mappedLogs = $.map(allData, function (item) { return new model.offerList(item) });
            self.offers(mappedLogs);

vm2

 self.offers = ko.observableArray([]).syncWith("offersLink");

Upvotes: 0

Views: 473

Answers (1)

user1813251
user1813251

Reputation: 339

figured it out!

self.offers = ko.observableArray([]).syncWith("offersLink");

should be

self.offers = ko.observableArray().syncWith("offersLink");

[] was always overwriting with an empty array

Upvotes: 2

Related Questions