1

如何获得视图的控制器

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()

4

1 回答 1

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();
}
于 2013-06-20T16:04:15.310 回答