我似乎无法从任何其他模块访问FotoAlbum的viewPort属性,也无法运行我尝试添加到FotoAlbum的任何功能。我是CommonJS的新手,所以它可能是一个简单的修复,但我现在没有看到它。
function FotoAlbum(app)
{
var self = Ti.UI.createWindow(
{
title : 'Fotoalbum',
backgroundColor : '#fff',
layout : 'vertical',
height : 'auto',
width : 'auto'
});
this.t=3;
self.add(app.Navigation.getNavigationBar(app));
this.viewPort = Ti.UI.createView(
{
top : '0dp',
left : '0dp',
width : '100%',
height : 'auto',
backgroundColor : 'white'
});
var label = Ti.UI.createLabel(
{
text : 'Foto album'
});
this.viewPort.add(label);
self.add(this.viewPort);
return self;
}
module.exports = FotoAlbum;
答案 0 :(得分:1)
this
指的是函数 FotoAlbum
的上下文,但您使用此函数创建并返回视图,这是为什么你不能访问函数上下文,因此附加到它的属性。
为了使这项工作成功,只需将您的方法和属性附加到View本身,如下所示:
function FotoAlbum(app) {
var self = Ti.UI.createWindow();
// Attach to the view
self.t=3;
self.add(app.Navigation.getNavigationBar(app));
self.viewPort = Ti.UI.createView();
var label = Ti.UI.createLabel({
text : 'Foto album'
});
self.viewPort.add(label);
self.add(self.viewPort);
return self;
}
module.exports = FotoAlbum;
修改强> 忘记提及,不要将对象附加到视图,然后更改该对象的属性,由于javascript代理在Titanium中的功能,这将无法工作。