[英]Do I need to add app.initialize() in all my html files in a cordova/phonegap project
I am making a phonegap/cordova project. 我正在制作一个phonegap / cordova项目。 I created a skeleton project using command line, as the guide suggests to making a new android/phonegap project.
我使用命令行创建了一个骨架项目,因为指南建议制作一个新的android / phonegap项目。
In the index.html file created there is a piece of code app.initialize()
, and the code it comes from a file called index.js. 在创建的index.html文件中,有一段代码
app.initialize()
,代码来自一个名为index.js的文件。
My question is, do I have to have this piece of code in all my html files, since i will be using jQueryMobile to do the front-end, I might need to have several html files. 我的问题是,我是否必须在我的所有html文件中都有这段代码,因为我将使用jQueryMobile来执行前端,我可能需要有几个html文件。
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 explicity 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);
}
};
Since all pages are called through Ajax calls, in theory you don't need to add that line in all your pages. 由于所有页面都是通过Ajax调用调用的,理论上您不需要在所有页面中添加该行。 But in some cases you might want to add it, for example if there might be a chance that the particular page might not be called from an ajax call, or a user for some strange reason lands on that page, instead of your index page.
但在某些情况下,您可能希望添加它,例如,如果可能无法从ajax调用调用特定页面,或者由于某些奇怪的原因而导致用户登陆该页面而不是索引页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.