Ti.App.fireEvent-Reference错误 Ti未被定义[英] Ti.App.fireEvent - Reference error Ti is not defined

本文是小编为大家收集整理的关于Ti.App.fireEvent-Reference错误 Ti未被定义的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有这个简单的钛JS脚本.

app.js

var win = Ti.UI.createWindow();
    var webview = Ti.UI.createWebView({
        url: 'logging.html'
    });
    webview.addEventListener('help',function(){
        alert('help');
    });
    win.add(webview);
    win.open();

logging.html

<html>
    <body>
        <a onclick="Ti.App.fireEvent('help')">Help</a>
    </body>
</html>

当我单击帮助链接时,控制台给我Reference Error: Ti is not defined.

我还尝试用钛更改Ti,但同样的错误.

------------------编辑--------------

此错误仅带有Web浏览器. iOS工作得很好.但是

当钛工作室编译Web移动设备的项目时,我可以看到Titanium.js和Ti/*文件夹,因此我想它无法加载Ti对象.谁能解释我为什么?

推荐答案

我找到了解决方案!

只需添加所有html页面的简单脚本

var Ti = window.parent.Ti

玩得开心!

编辑:

从SDK版本3.0.2GA上开始,我想他们将其修复了.现在,它称为Ti SDK,没有该黑客!**

其他推荐答案

首先,更改:

webview.addEventListener('help',function(){
    alert('help');
});

to:

Ti.App.addEventListener('help',function(){
    alert('help');
});

和第二个:在您的html文件中呼叫" ti.app.fireevent()".

其他推荐答案

经过一些测试,我发现先前的代码在iOS Phisical Device/Simulator和Android上完美工作.

它不在Android Web浏览器仿真器和普通移动浏览器(移动Web应用程序)

因此,由于"正常的JavaScript库没有Titanium.*或Ti.*",似乎钛API调用永远不会在Web浏览器上使用.

本文地址:https://www.itbaoku.cn/post/1938197.html

问题描述

I have this simple Titanium js script.

app.js

var win = Ti.UI.createWindow();
    var webview = Ti.UI.createWebView({
        url: 'logging.html'
    });
    webview.addEventListener('help',function(){
        alert('help');
    });
    win.add(webview);
    win.open();

logging.html

<html>
    <body>
        <a onclick="Ti.App.fireEvent('help')">Help</a>
    </body>
</html>

when I click on the Help link, the console gives me Reference Error: Ti is not defined.

I also tried changing Ti with Titanium, but same error.

------------- EDIT ----------

this error comes only with web browser. iOS works perfectly. but

when titanium studio compiles the project for web mobile, I can see titanium.js and TI/* folder, so I guess it can't load Ti object. can anyone explain me why?

推荐答案

I found a solution!

simply add to all of your html pages the simple script below

var Ti = window.parent.Ti

have fun!

EDIT:

from sdk version 3.0.2GA on, I guess they fixed it. now it calls Ti sdk without that hack!**

其他推荐答案

First, change:

webview.addEventListener('help',function(){
    alert('help');
});

To:

Ti.App.addEventListener('help',function(){
    alert('help');
});

And second: Call "Ti.App.fireEvent()" without the final "s" in your HTML file.

其他推荐答案

after some tests, I found that the previous code works perfectly on iOS phisical device/simulator and Android.

it doesn't on android web browser emulator and normal mobile browser (Firefox as mobile web app)

so, it seems that Titanium api calls will never work on web browsers because of "normal javascript library doesn't have Titanium.* or Ti.*".