0

I am creating an object like this:

  markers[name] = {};
  markers[name].id = id;
  markers[name].lat = lati;
  markers[name].lng = longi;
  markers[name].state = state;
  markers[name].position = posi;
  markers[name].selected = false;

then i have a new function where i want to loop through the markers object and change the marker image .selected has been set to true.

Here is what i have tried:

function setMarkerImage() { 

        for (var key in markers) { 
           console.log("test 1: " + key + key.selected);
            if (key.selected === true)
          {
          console.log("test 2");        
             var newImage = new google.maps.MarkerImage('img/presence/' + state + '_sel.png');
             var marker = $("#dispatcher").gmap3({action: 'get', name:'marker', tag: key})
               if (marker){
               marker.setIcon(newImage);
               }
          }
        } 
} 

Problem is i am getting

test 1: Vinceundefined 

in the console, i take it i cannot use key.selected like this?

1
  • 2
    It should be markers[key].selected . Commented Jul 4, 2012 at 12:20

1 Answer 1

3

key isn't an object, so it hasn't a selected key. Try instead with

console.log("test 1: " + key + markers[key]["selected"]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.