我想解決如何訪問我的requireJS JavaScript中的Intl-Tel-Input庫。我有以下代碼,並且我需要將回調放在requireJS模塊之外,因爲它正在被第三方代碼訪問。在JavaScript中訪問第三方加載的requireJS包
如何訪問callback
函數中的intlTelInput
代碼?
在我的樹枝模板:
<script type="text/javascript">
require(['crmpicco/details'], function(details) {
details.init();
});
var callback = function (response) {
// I want to access intlTelInput in here
};
</script>
我有這個在我的config.js
:
require = {
baseUrl: '/assets/js',
paths: {
'intl-tel-input': '/assets/vendor/intl-tel-input/build/js/intlTelInput.min',
},
shim: {
'intl-tel-input': {
deps: ['libphonenumber-utils']
},
}
};
在他們的源代碼中他們支持UMD,所以我猜你可以使用'require(['intl-tel-input'],function(IntlTelInput){};'內部回調。並且不需要墊片。 – Andrey
@Andrey你知道應該如何實施嗎?如果'callback'在'require'中,那麼第三方代碼就找不到回調函數。 – crmpicco
@Andrey同樣,如果'require'在'callback'中,那麼intlTelInput就不能被找到。 'TypeError:intlTelInput不是函數'。 – crmpicco