我目前正在使用requireJS开发Phonegap应用。 在iOS和Android平台上,我的代码运行得很好,但在WP8平台上,main.js文件(requireJS的data-main)被调用/执行两次。 然后它会触发两个deviceReady事件并执行ajax请求,所以这不好!
我似乎无法找到问题所在。 这是我的代码的一部分。
的index.html
<script src="cordova.js" type="text/javascript"></script>
<script data-main="js/app/main" src="js/libs/require/require.js" type="text/javascript"></script>
main.js
requirejs.config({
baseUrl: 'js/app',
paths: {
// Libs
domReady:'../libs/require/domReady',
jquery: '../libs/jquery/jquery-1.11.0.min',
knockout: '../libs/knockout/knockout-3.1.0.min',
kopostbox: '../libs/knockout/knockout-postbox.min',
sammy: '../libs/sammy/sammy.min',
amplify: '../libs/amplify/amplify.min',
moment: '../libs/moment/moment-2.6.0.min',
underscore: '../libs/underscore/underscore',
owlcarousel: '../libs/owlcarousel/owl.carousel.min',
viewport: '../libs/viewport/viewport.min',
autosize: '../libs/autosize/jquery.autosize.min',
imagesloaded: '../libs/imagesLoaded/imagesloaded.pkgd.min',
details: '../libs/details/jquery.details.min'
},
shim: {
jquery: {
exports: '$'
},
knockout: {
exports: 'ko'
},
kopostbox: {
deps: ['knockout']
},
sammy: {
deps: ['jquery'],
exports: 'Sammy'
},
amplify: {
deps: ['jquery'],
exports: 'amplify'
},
underscore: {
exports: '_'
},
owlcarousel: {
deps: ['jquery'],
exports: 'owlcarousel'
},
viewport: {
deps: ['jquery']
},
imagesloaded: {
deps: ['jquery']
},
details: {
deps: ['jquery']
}
}
});
require([
'domReady',
'app',
'owlcarousel',
'ko.customBindingHandlers',
'viewport',
'imagesloaded',
'details'
],
function(domReady, app){
domReady(function () {
app.initialize();
});
});
起初,我想到了与cordova的冲突,但由于它在iOS和Android中运行良好,我认为它不可能。 我尝试删除数据主要属性并为main.js插入脚本标记,但它并没有改变。
如果有人能指出我正确的方向,请帮忙!