【发布时间】:2016-11-10 18:11:25
【问题描述】:
我在 Web 应用程序中使用 Bing Maps V8 Web Control。我还使用早午餐来管理静态资产,包括 JavaScript。默认情况下,Brunch 将所有非供应商 JavaScript 代码包装在 CommonJS 模块中。
Microsoft 的文档说要在脚本导入 URL 中使用回调参数初始化控件,如下所示:
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?branch=release&callback=loadMapScenario' async defer></script>
loadMapScenario 定义如下:
Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', {
callback: onLoad,
errorCallback: onError,
credentials: 'Your Bing Maps Key'
});
function onLoad() {
var options = { maxResults: 5 };
var manager = new Microsoft.Maps.AutosuggestManager(options);
manager.attachAutosuggest('#searchBox', '#searchBoxContainer', selectedSuggestion);
}
function onError(message) {
document.getElementById('printoutPanel').innerHTML = message;
}
function selectedSuggestion(suggestionResult) {
document.getElementById('printoutPanel').innerHTML =
'Suggestion: ' + suggestionResult.formattedSuggestion +
'<br> Lat: ' + suggestionResult.location.latitude +
'<br> Lon: ' + suggestionResult.location.longitude;
}
问题是我从 API 收到一个错误,说回调函数无效。
有没有更好的方法来做到这一点?有没有办法让 web 控件以这种方式调用 CommonJS 包装的函数?
【问题讨论】:
标签: javascript bing-maps commonjs brunch