简体   繁体   中英

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");

figured it out!

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

should be

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

[] was always overwriting with an empty array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM