从getView()调用一个控制器

时间:2013-06-20 14:03:31

标签: javascript titanium

如何获取视图的控制器

var c = Alloy.createController('win', activeTab);
c = c.getView();
Wins.push(c);

在控制器赢了我有功能

exports.fun = function() {

};

从控制器获得胜利之后是视图如何从视图中调用此函数我需要控制器来调用函数

for ( i = 0; i < Wins.length; i++) {
Wins[i].fun();
}

Wins [i]是一个视图如何获得此视图的控制器,以便我可以调用函数fun()

1 个答案:

答案 0 :(得分:3)

不要推动窗户,推动控制器

// this is a bad name for a controller...
var controller = Alloy.createController('win', activeTab);
var view = controller.getView();

// save the controller to a list of global controllers
Alloy.Globals.Controllers = Alloy.Globals.Controllers || {};
Alloy.Globals.Controllers['aController'] = controller;


// loop through all controller and execute func if it exists
for ( var i in Alloy.Globals.Controllers) {
   Alloy.Globals.Controllers[i].fun && Alloy.Globals.Controllers[i].fun();
}