【发布时间】: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 -
有效!谢谢!