我正在为新工作开发一个 Flex 应用程序。这有点像一个训练轮应用程序——我正在学习这门语言,这不是一个需要与服务对话才能完成工作的应用程序。整个应用程序中有一些组合框实例共享相同的一组可能值(例如,选择状态:“进行中”、“拒绝”、“完成”),我希望它们使用相同的数据源。
管理这个问题的最佳方法是什么?
MVC 架构 ....在简单的情况下只是模型部分:
package
{
[Bindable]
public final class ShellModelSingleton
{
public var selectedStatus:ArrayCollection;
////////////////////////////////////////////
// CONSTRUCTOR
// ****DO NOT MODIFY BELOW THIS LINE*******
///////////////////////////////////////////
public function ShellModelSingleton(){}
/****************************************************************
* Singleton logic - this makes sure only 1 instance is created
* Note: you are able to hack this since the constructor doesn't limit
* a single instance
* so make sure the getInstance function is used instead of new
* ShellModelSingleton()
*****************************************************************/
public static function getInstance():ShellModelSingleton {
if(_instance == null) {
_instance = new ShellModelSingleton();
}
return _instance;
}
protected static var _instance:ShellModelSingleton;
}
}
然后您可以从任何组件更新和使用单例,如下所示:
[Bindable] private var model:ShellModelSingleton =
ShellModelSingleton.getInstance();
组件1
<mx:DataGrid id="myDG" dataProvider="{model.selectedStatus}" />
组件2
<mx:List id="myList" dataProvider="{model.selectedStatus}"
labelField="label" />
然后,您对 selectedStatus 集合所做的任何更改都将在两个组件中更新。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)