Titanium 合金,需要外部JS
现在我的Titanium 合金,需要外部JS,titanium,appcelerator,titanium-alloy,Titanium,Appcelerator,Titanium Alloy,现在我的alloy.js文件中有一个全局函数 Alloy.Globals.indicator = function(parent) { var view = Ti.UI.createView({ width: '100%', height: '100%', backgroundColor: '#000', opacity: 0.6, visible: false }); function osIndicatorStyle() {
alloy.js
文件中有一个全局函数
Alloy.Globals.indicator = function(parent)
{
var view = Ti.UI.createView({
width: '100%',
height: '100%',
backgroundColor: '#000',
opacity: 0.6,
visible: false
});
function osIndicatorStyle()
{
style = Ti.UI.iPhone.ActivityIndicatorStyle.PLAIN;
if ('iPhone OS' !== Ti.Platform.name) style = Ti.UI.ActivityIndicatorStyle.DARK;
return style;
};
var activityIndicator = Ti.UI.createActivityIndicator({
style: osIndicatorStyle(),
height: Ti.UI.FILL,
width: 100
});
view.add(activityIndicator);
parent.add(view);
function openIndicator()
{
view.visible = true;
activityIndicator.show();
}
view.openIndicator = openIndicator;
function closeIndicator()
{
activityIndicator.hide();
view.visible = false;
}
view.closeIndicator = closeIndicator;
return view;
};
我不希望将这个大函数作为全局函数,而是使用require
将它导入到我需要的文件中
我已经搜索过了,但无法首先确定该文件放置在何处,然后确定如何实际“需要”该文件
所有这些只是创建一个视图,作为带有活动指示器的模式视图。该函数还包括两个显示和隐藏它的函数。在“app”文件夹中创建一个名为“lib”的文件夹
在此文件夹中,创建一个名为“任意”的文件,例如functions.js:
var functionName = function(){
//your function code here
}
exports.functionName = functionName;
在控制器中:
var functions = require('functions');
functions.functionName();
您可能还想看看哪些是具有视图/控制器/样式的可重用组件,因为我认为这会更好地满足您的需求
您应该为类似的东西创建一个
小部件。谢谢你,菲尔。我将看一看小部件,但看起来这两个部件都可以工作。是的,两者都可以工作,使用小部件只是意味着您可以获得更好的结构(视图的XML等)