Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could subscribe to your array like this:</p> <pre><code>ar.subscribe(function() { // clean and redraw all markers }); </code></pre> <p>If you do that, you will receive a notification when an item is added/removed to/from the array. BUT not when an property of an item is modified.</p> <p>If you want to update your google maps markers based on individual property changes in items, you could implement a <a href="http://www.knockmeout.net/2011/05/creating-smart-dirty-flag-in-knockoutjs.html" rel="nofollow">simple dirty flag mechanism</a> and then subscribe individually to each item. Since each item has an id, which I presume is unique, you could create a map with key/value pairs being the id and the map widget. </p> <p>So, given each individual item:</p> <pre><code>var item = function(data) { var self = this; self.isChanged = ko.observable(self); self.id = data.id; self.title = ko.observable(data.title); self.title.subscribe(function() { self.isChanged(self); self.isChanged.valueHasMutated(); }); self.lat = ko.observable(data.lat); self.lat.subscribe(function() { self.isChanged(self); self.isChanged.valueHasMutated(); }); self.lng = ko.observable(data.lng); self.lng.subscribe(function() { self.isChanged(self); self.isChanged.valueHasMutated(); }); } </code></pre> <p>And given a hypothetic map where you keep a link between your markers and the items:</p> <pre><code>var markersMap = []; markersMap[0] = yourGoogleMapWidget; </code></pre> <p>You can then subscribe to track changes on items like this:</p> <pre><code>ar[0].isChanged.subscribe(function(item) { var myGMapMarker = markersMap[item.id()]; // update your marker, or destroy and recreate it... }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload