跨平台应用开发:从理论到实践
1. 跨平台应用开发基础
在跨平台应用开发中,Model - View - Controller(MVC)模式是核心架构,同时,Widget 框架可用于开发完全自包含的可重用组件。以下是一个使用 Alloy 创建 Widget 的示例代码:
<Alloy> <Window> <Require type="widget" defaultState="off"/> </Window> </Alloy>在控制器中实例化 Widget 的编程方法如下:
// create the widget var toggleBtnWidget = Alloy.createWidget("buttonToggle", null, { "defaultState": "on", "id" : "toggleBtnWidget" }); // get the main view from the widget $.mainWindow.add(toggleBtnWidget.getView()); // open the window $.mainWindow.open();