javascript - Class method with google maps event listener run external function -
sorry question title, hard find one...
i have class handle google maps , 1 of methods create custom control:
// method: map.prototype.addbutton = function (order, onclickevent) { var = this; var buttonui = $.get('/templates/order-button.html', function (data) { var button = $(data)[0]; $(button).attr('id', order.id); $(button).find('span:eq(1)').text('#' + order.id); google.maps.event.adddomlistener(button, 'click', function() { onclickevent; }); }); }
as can see added click
event. click should open modal window.
when use method i'm doing:
var map = new map(); map.addbutton(order, openmymodal());
unfortunately open modal page load.
i tried well:
var map = new map(); map.addbutton(order, function() { openmymodal(); });
so, question is, how can attach open modal window function google maps event listener?
var map = new map(); map.addbutton(order, openmymodal());
should be
var map = new map(); map.addbutton(order, openmymodal);
you want pass function, not result of function second parameter
and
google.maps.event.adddomlistener(button, 'click', function() { onclickevent; });
should be
google.maps.event.adddomlistener(button, 'click', function() { onclickevent(); });
here want execute passed in function
Comments
Post a Comment