【问题标题】:Titanium alloy : get current window from required view钛合金:从所需视图获取当前窗口
【发布时间】:2016-10-11 02:38:44
【问题描述】:

我有以下代码(index.js):

<Alloy>
  <Window id="home" >
    <View id="formulaire">
	  <Require type="view" id="etape_1_form" src="form/etape_1" />
	</View>
  </Window>
</Alloy>

在 etape_1_form.xml 上,我必须使用来自 danielhanold.pickerwidget 的选择器小部件

这是在 etape_1_form.js(控制器)中使用这个小部件的简单方法:

Alloy.createWidget('danielhanold.pickerWidget', {
  id: 'mySingleColumn',
  outerView: $.home,
  hideNavBar: false,
  type: 'single-column',
  selectedValues: [20],
  pickerValues: [{10: 'Auburn', 20: 'Bald', 30: 'Black', 40: 'Blond', 50: 'Brown'}],
  onDone: function(e) {
    // Do something
  },
});

$.form_win.open();

现在不是打开选择器,而是抛出错误,因为我无法从该行访问当前窗口:

outerView: $.home
The error : "undefined is not an object (evaluating 'outerView.add')

当我将选择器移动到 index.js(主控制器)时,选择器可以工作,但是我有许多必需的表单并且想要组织我的代码,所以我喜欢将每个表单 js 代码放在它的控制器文件中。

那么我如何从所需视图访问 $.home 窗口?谢谢你的帮助。

【问题讨论】:

    标签: titanium titanium-mobile titanium-alloy appcelerator-titanium titanium-android


    【解决方案1】:

    不,你不能直接。

    但您可以使用“全局变量”轻松避免这种情况。

    在 index.js 上:

    Alloy.Globals.indexController = $;
    

    在 etape_1_form.js 上

    outerView: Alloy.Globals.indexController.home
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多