【问题标题】:Titanium : How to load an external custom AlertDialog in Alloy?Titanium:如何在 Alloy 中加载外部自定义 AlertDialog?
【发布时间】:2015-02-17 22:37:10
【问题描述】:

我所有的项目都是用 Alloy 编写的,所以这里没有经典的 Titanium。 我想在我的索引中加载一个外部自定义 AlertDialog(位于views/popup.xml 中)。所以我需要显示一个警报并通过单击“确定”按钮将其销毁(例如)。帮助按钮应该执行另一个操作。

我的 popup.xml 文件:

<Alloy>
    <AlertDialog id="popup" title="Error popup"
        message="There is an error" cancel="1">
        <ButtonNames>
            <ButtonName>OK</ButtonName>
            <ButtonName>Help</ButtonName>
        </ButtonNames>
    </AlertDialog>
</Alloy>

我的 index.js 文件:

function openPopup(e) {
    var page = Alloy.createController('views/popup').getView();
    page.show();
};
openPopup();

但这给了我一个错误:

  • [调试] [iphone, 8.1, 192.168.0.1] 本机 模块:合金/控制器/视图/弹出窗口
  • [错误] [iphone, 8.1, 192.168.0.1] 找不到模块: 合金/控制器/视图/弹出窗口
  • [ERROR] [iphone, 8.1, 192.168.0.1] TypeError: 'undefined' is not a 构造函数(评估 'new (__p.require("alloy/controllers/" + 名称))(args)')

我没有 popup.js,也不需要 index.js 中的任何文件。所以我的问题是:如何动态加载控制器?如何在“单击”操作中使用 addEventListener 删除(或销毁)它?谢谢。

【问题讨论】:

  • 只使用Alloy.createController('popup').getView();,而不是views/popup
  • 有效!谢谢!

标签: titanium titanium-alloy


【解决方案1】:

同意乌龟。当您创建控制器时,它会隐含地知道您指的是 app/views 目录中的视图。

并且您应该通过不创建局部变量来稍微改进您的代码(用于垃圾收集目的)。所以而不是:

var page = Alloy.createController('views/popup').getView();
page.show();

你应该这样做:

Alloy.createController('views/popup').getView().open();

您可以在splendid article by Fokke Zandbergen 中找到有关此的更多信息。

/约翰

【讨论】:

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