简体   繁体   English

我是否需要在cordova / phonegap项目中的所有html文件中添加app.initialize()

[英]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.

相关问题 CordovaApp-AngularJs-app.initialize()->未定义不是函数 - CordovaApp - AngularJs - app.initialize() -> undefined is not a function 无法将Cordova插件添加到我的PhoneGap项目中 - Can't add a Cordova plugin to my PhoneGap project Cordova / Phonegap应用程序未显示我在jade文件中所做的更改 - Cordova/Phonegap app is not showing the changes I've made in the jade files 对于Angular2项目,我如何连接从typescript生成的所有JavaScript文件并将它们添加到我的index.html文件中 - For Angular2 project, In gulp how do I concat all my JavaScript files that were generated from typescript and add them to my index.html file Cordova-我怎么知道我的应用程序是使用HTML5 Geolocation API还是Cordova Geolocation插件? - Cordova - how do I know if my app is using the HTML5 Geolocation API or the cordova geolocation plugin? 混淆整个phonegap angularjs项目(我所有的JavaScript文件) - obfuscating whole phonegap angularjs project (all my javascript files) PhoneGap / Cordova应用程序基于Swift项目 - PhoneGap/Cordova App based on Swift Project 如何使用 onDeviceReady 设置 AngularJS 应用程序并为 Cordova 初始化函数? - How do I setup an AngularJS app with onDeviceReady and initialize functions for Cordova? Phonegap / Cordova中带有插件的多个HTML文件和文件夹? - Multiple HTML files and Folders in Phonegap/Cordova with plugins? 我需要一个条形码扫描仪将它包含在我的phonegap项目中 - I need a Barcode Scanner to include it in my phonegap project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM