我的主要問題是使用require.js時,我的函數不再是Global。所以當我從我的phtml文件中調用它時,它並沒有被發現。任何想法什麼是在我的js文件全局內部生成一個函數的正確方法?我嘗試了多種方法/我在網上找到的答案,但似乎沒有任何工作。有什麼建議麼?Magento 2:如何調用js函數在我的Requirement.js文件中,從phtml文件
這裏是我的js文件
define([
'jquery'
], function ($) {
return function (config) {
console.log(config);
}
function initMap() {
console.log('initMap is being called');
}
});
我requirejs-config.js文件:
var config = {
map: {
'*': {
'gslMap': ['Gauge_StoreLocator/js/app']
}
}
};
我PHTML文件:回調函數 「initMap」 被稱爲在結束
<script async defer src="https://maps.googleapis.com/maps/api/js?key=<?php echo $this->getGoogleApi(); ?>&callback=initMap">