Cordova项目中的index.js是否必要? [英] Is index.js in cordova project necessary?

查看:49
本文介绍了Cordova项目中的index.js是否必要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Do I have to keep this file (www/js/index.js) or can I delete it and put my project files instead?

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文件,我自己正在处理设备就绪事件.

I used to work with Cocoon.io and there were no index.js file, i was handling deviceready event myself.

推荐答案

只要正确绑定了 deviceready 事件,就可以替换或删除 index.js 完全.确保您还从 index.html 一致地更新了JS引用.

As long as you are properly binding the deviceready event, you can replace or delete the index.js entirely. Make sure you also update your JS references from index.html accordinygly.

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

If nothing works when you test the app, it means you have broken the onDeviceReady handler.

这篇关于Cordova项目中的index.js是否必要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆