Pass parameter to callback function

前端 未结 4 1903
有刺的猬
有刺的猬 2021-02-20 16:35

My code

// do ajax request and get JSON response

for (var i = 0; i < data.results.length; i++) {  
    result = data.results[i];
    // do stuff and c         


        
4条回答
  •  一个人的身影
    2021-02-20 16:52

    try this one

    var marker = new Array();
    for (var i = 0; i < data.results.length; i++) {  
        result = data.results[i];
        // do stuff and create google maps marker    
        marker[i] = new google.maps.Marker({  
            position: new google.maps.LatLng(result.lat, result.lng),   
            map: map,  
            id: result.id  
        });  
        google.maps.event.addListener(marker[i], 'click', example(marker[i].id));  
    
    }
    

    create new function

    function example(my_window){
        return function(){
            createWindow(my_window);
        }
    }
    

提交回复
热议问题