jQuery mobile undefined error Cordova。

时间:2016-06-15 19:48:27

标签: javascript jquery cordova jquery-mobile

所以我对Cordova场景非常陌生,对jQuery移动场景更是如此。我只是试图让我在应用程序中的事件解雇并且感到沮丧,因为我正在完成所有文档和教程所说的事情。

这是我的样式脚本布局:

<link rel='stylesheet' href="js/jquery/mobile/jquery.mobile-1.4.5.css" />
<script src="js/jquery/jquery.min.js"></script>
<script src="js/jquery/mobile/jquery.mobile-1.4.5.min.js"></script>
<script src="js/index.js"></script>

jquery是3.0.0版本

这是我的index.js

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

无论我做了什么,无论我如何设置index.js或我使用的是什么版本的jquery(我一直回到1.10),我仍然在加载时出现此错误

query.mobile-1.4.5.js:3337 TypeError: undefined is not an object (evaluating 'a.event.props.concat') 

这个错误对我没有任何意义,我已经重组并重建了一个简单的hello world应用程序,只需点击几次,什么都没得到。我希望有人可以向我解释我做错了什么,或者给我一个解决方法,因为没有任何帮助。

1 个答案:

答案 0 :(得分:2)

你必须在你的html中包含cordova.js文件才能触发deviceready事件。查看此链接 - http://cordova.apache.org/docs/en/6.x/cordova/events/events.html#page-toc-source

确保Cordova在调用其组件之前完全加载。