gpt4 book ai didi

javascript - 引用错误:函数未定义

转载 作者:行者123 更新时间:2023-11-28 18:18:25 25 4
gpt4 key购买 nike

我正在尝试调用 JavaScript 方法。我在运行时通过字符串连接构建 html。

$scope.getRoute = function (isRouteFormValid) {
routingDemoPageService.executeService(serviceURL, 'admin', 'admin').then(function (response) {
function tryingOnceAgain() {
alert('called.....');
}

var markers = L.markerClusterGroup({
showCoverageOnHover:false,
chunkedLoading: true
});

var geojsonLayer = L.geoJson(response, {
onEachFeature: function(feature, layer){

var UIDValue = (feature.properties['uid'] !== null ? Autolinker.link(String(feature.properties['uid'])) : '');

var popupContent = '<table>' +
'<tr><th scope="row"><a href="javascript:tryingOnceAgain()">Edit</a></th><td></td></tr>' +

'<tr><th scope="row">uid</th><td>' + UIDValue + '</td></tr></table>';

layer.bindPopup(popupContent);
}
});
markers.addLayer(geojsonLayer);
$scope.map.addLayer(markers);
$scope.map.fitBounds(markers.getBounds());

})['catch'](function (error) {

});

}

当我单击调用 TryOnceAgain 方法的链接时,我收到以下错误

ReferenceError: tryingOnceAgain is not defined

我不确定为什么会出现以下错误。

有人可以指出我做错了什么吗?

最佳答案

javascript:tryingOnceAgain() 引用了全局范围内的函数,但您在 function (response) { 范围内定义了 tryingOnceAgain 函数.

要解决此问题,您必须将 tryingOnceAgain 函数移至全局范围。

或者只是将其分配给window对象而不改变物理位置:

window.tryingOnceAgain = function() {...}

关于javascript - 引用错误:函数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40421345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com