[英]How do i remote include a javascript file in Titanium appcelerator and use the functions of that file?
I am required to remotely include into my appcelerator project, a javascript file available at a particular link, and use the function declared in that file to process some data. 我需要将包含在特定链接上的javascript文件远程包含到我的appcelerator项目中,并使用该文件中声明的函数来处理一些数据。
What i would like to achieve is something like the following in html - 我想实现的是类似于html中的以下内容-
<script src="https://some-link/Data.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var testVariable = someMethod(localdata);
});
//use testVariable as necessary
</script>
//someMethod() is declared in remotely available Data.js // someMethod()在远程可用的Data.js中声明
I am a newb at Appcelerator and im not really able to follow some of the threads i have come across, so some detailed help would be really appreciated. 我是Appcelerator的一名新手,我无法真正追踪我遇到的一些线程,因此,非常感谢您提供一些详细的帮助。 Thank you in advance.
先感谢您。
Well according to me , you should first understand few points first : 根据我的说法,您首先应该首先了解以下几点:
Now coming to your problem , as you said that you want to fetch some data only from remote server by triggering some JS function from remote file. 现在谈到您的问题,正如您所说的,您只想通过从远程文件中触发一些JS函数来仅从远程服务器中获取一些数据。 So following is what would I do :-
所以下面是我该怎么做:-
a/ Create a hidden webview in my main window with a EventListener of webview. A /创建一个隐藏的WebView具有的WebView的事件监听在我的主窗口。 Something like :
就像是 :
var webview = Titanium.UI.createWebView({url:'localHtmlFile.html'});
//event listener to handle the response from webview
Ti.App.addEventListener('fromWebView', function(e)
{
var testVariable = e.data;
});
b/ In localHtmlFile.html file : b /在localHtmlFile.html文件中:
<!DOCTYPE html>
<html>
<body>
<script src="https://some-link/Data.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var testVariable = someMethod();
//respond the fetch data to the main window via fireEvent
Ti.App.fireEvent( 'fromWebView', { data : testVariable } );
});
</script>
</body>
</html>
PS : This is just a logic to begin with , you have to edit code according to your requirements PS:这只是一种逻辑,您必须根据需要编辑代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.