cordova项目中的index.js是否必要?

时间:2018-05-16 10:27:04

标签: cordova

我是否必须保留此文件(www / js / index.js)或者我可以删除它并放置我的项目文件吗?

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.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();

我曾经使用过Cocoon.io而且没有index.js文件,我自己正在处理deviceready事件。

1 个答案:

答案 0 :(得分:1)

只要您正确绑定deviceready事件,就可以完全替换或删除index.js。确保您还从index.html accordinygly。

更新JS引用

如果您在测试应用时没有任何效果,则表示您已经破坏了onDeviceReady处理程序。

相关问题