Appcelerator Titanium Alloy开发全解析
1. 控制器与视图交互示例
在示例控制器文件中,有一个之前提到的doClick函数。通过$变量,控制器能够访问视图中的控件,例如hello_label和main_window。以下是示例代码:
// local/private function function doClick(e) { alert($.hello_label.text); } // public exported function than can be accessed by other // controllers exports.changeLabelText = function(_text) { $.hello_label.setText(_text); } // $ Represents current scope of controller, open the window // main_window that was defined in the view.xml $.main_window.open();大多数应用程序会有多个模型、控制器和视图,这样的结构有助于应用程序的架构设计和维护。
2. 使用Appcelerator Alloy与MVC框架
Appcelerator Alloy将MVC框架直接映射到其项目文件结构中。它还包含了