2016-08-09 33 views
1

我有問題來解析數據從addListener到另一個函數,我嘗試但'數據'解析失敗。能不能幫我傢伙...如何解析addListener中的數據javascript

這是我的代碼

var data = 'myname'; 
bermudaTriangle.addListener('click', showArrays(data); 


function showArrays(event, data) { 
    // Since this polygon has only one path, we can call getPath() to return the 
    // MVCArray of LatLngs. 
    var vertices = this.getPath(); 

    var contentString = data; 

    // Replace the info window's content and position. 
    infoWindow.setContent(contentString); 
    infoWindow.setPosition(event.latLng); 

    infoWindow.open(map); 
} 
+0

你傳遞給聽衆的'showArrays(數據)調用的結果'但是你只需要參考'bermudaTriangle.addListener( '點擊',showArrays);' – MysterX

+0

你需要檢查你的語法... – gcampbell

回答

0

你爲什麼不嘗試一下:

bermudaTriangle.addListener('click', showArrays.bind(this, data)); 
0

謝謝你們,我的問題已經完成。

這個代碼..

bermudaTriangle.addListener('click', (function(event){ 
    var nama = 'myname'; 
    showArrays(event, nama); 
})); 
function showArrays(event, data) { 
    // Since this polygon has only one path, we can call getPath() to return the 
    // MVCArray of LatLngs. 
    var contentString = nama; 
    // Replace the info window's content 
    infoWindow.setContent(contentString); 
    infoWindow.setPosition(event.latLng); 
    infoWindow.open(map); 
}