繁体   English   中英

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

[英]Do I need to add app.initialize() in all my html files in a cordova/phonegap project

我正在制作一个phonegap / cordova项目。 我使用命令行创建了一个骨架项目,因为指南建议制作一个新的android / phonegap项目。

在创建的index.html文件中,有一段代码app.initialize() ,代码来自一个名为index.js的文件。

我的问题是,我是否必须在我的所有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);
    }
};

由于所有页面都是通过Ajax调用调用的,理论上您不需要在所有页面中添加该行。 但在某些情况下,您可能希望添加它,例如,如果可能无法从ajax调用调用特定页面,或者由于某些奇怪的原因而导致用户登陆该页面而不是索引页面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM