Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Vince, without seeing what's in 'fencesCookie' or what's in your 'markers' object it is hard to say but it's either:</p> <ol> <li><p>[Less likely] You have multiple matching id's in your 'markers' object and it's causing the '(markers[key].id === id)' to give a positive result each time and jumping into the cookie loop again.</p></li> <li><p>[Most Likely] Your test for a matching key in 'fencesCookie' is failing for all cases except when it matches so you're printing out a 'No Fence' button for each key in 'fenceCookie'or for all but one key.</p></li> </ol> <p>I changed the order and added a variable to check for a match after the loop has finished. Try this out (or something like it):</p> <pre><code>function fenceButton(id) { for (var key in markers) { if (markers[key].id === id) { // set a variable to test if we find a match // we'll set it to true if we find one var match = false; // Test that fencesCookie exists if ($.isEmptyObject(fencesCookie)) { // if not menu.add('No Fence', 'nofence', function(){ menu.close(); }); } else { // if it does $.each(fencesCookie, function (i, f) { // loop through the cookie and match on the f.contact if (key === f.contact) { // set match to true match = true; // create the 'view' button menu.add(strings[strLang].viewfence, 'fence', function(){ viewFence(f.lat, f.lng, f.radius); menu.close(); }); } }); // The loop is done so test 'match' to see if we found a match if (match === false) { // No matches so create the 'No Fence' button console.log("No Fence : "+key+" "+f.contact) } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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