【发布时间】:2016-06-15 19:48:27
【问题描述】:
所以我对 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 应用程序,几次都没有得到任何结果。我希望有人可以向我解释我做错了什么,或者告诉我一个修复,因为没有任何帮助。
【问题讨论】:
-
您必须在 html 中包含 cordova.js 文件才能触发 deviceready 事件。看看这个链接 - cordova.apache.org/docs/en/6.x/cordova/events/…
-
感谢您的帮助,但我决定走一条不同于 jquery mobile 的路线。我发现角度要好得多。
-
但是我的解决方案有效吗?即使您转向 Ionic 等基于 Angular 的框架,您仍然需要包含此文件,并且事件可能是平台就绪而不是设备就绪
-
是的,但这对我们来说不是一个理想的设置,所以我们选择了不同的路线
-
为了他人的利益发布了答案。希望它有用。祝你好运马克
标签: javascript jquery cordova jquery-mobile