【问题标题】:Titanium / Alloy widgets and controllers钛/合金小部件和控制器
【发布时间】:2013-07-11 17:08:13
【问题描述】:

我正在使用 AlloySliderMenu 小部件使用 Titanium SDK 3 构建应用程序。

这个小部件创建一个类似于 Facebook 应用程序的滑块菜单。听起来它很容易使用,但我正面临以下问题。

在 index.xml 中我需要小部件。

在应用程序的 index.js 中,我有以下一段代码:

currentView = Alloy.createController('list').getView();
//ds is the slider menu id
//contentview in the main panel of the menu
$.ds.contentview.add(currentView);

这将在应用程序的主窗口中打开我的“列表”视图。

问题是,在我的 list.js 控制器中,我有一个函数应该通过按钮的单击操作将 $.ds.contentview 内容更改为另一个视图。 但我无法从列表容器访问 $.ds.contentview 并使用此对象。

我已经尝试过 Alloy.createWidget 等。但没办法,它不会工作。

【问题讨论】:

    标签: controller widget titanium titanium-alloy


    【解决方案1】:

    如果您的问题是范围,可以使用全局变量或 CFG 变量快速修复:

    Alloy.Globals.someGlobalObject = { key: 'value' };
    Alloy.Globals.someGlobalFunction = function(){};
    
    var theObject = require('alloy').Globals.someGlobalObject;
    

    这里有更多关于使用这个变量的信息:http://docs.appcelerator.com/titanium/latest/#!/api/Alloy

    如果这不能解决问题,您可以在创建控制器时在 JSON 对象中发送参数,例如:

    Alloy.createController('list', {
            title : "Unable to login",
            message : authData.FailureReason,
            callback : callbackFunc
        }).getView()
    

    也许回调函数可以帮助你。

    【讨论】:

      【解决方案2】:

      正如马里奥所说: 在 index.js 中,使用全局: Alloy.Globals.ds = $.ds;

      在 list.js 中,您可以通过以下方式访问小部件: Alloy.Globals.ds

      【讨论】:

        猜你喜欢
        • 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
        相关资源
        最近更新 更多