FLEX中ViewStack刷新解决方案

在ViewStack的生命周期中仅只会加载一次view,对于某些业务来说这样的加载方式不大合适,有没有一种办法在每次切换NavigatorContent的时候都重新加载view呢?

办法是有的,直接上代码

    <mx:ViewStack id="viewStack1" bottom="0" right="0" top="0" left="0" change="viewStack1_changeHandler(event)">
<s:NavigatorContent width="100%" height="100%" label="列表" icon="@Embed(source='http://www.cnblogs.com/http://www.cnblogs.com/__assets/icon/main/36/list.png')">
<view:CommodityListView id="listView" width="100%" height="100%"
showAddView
="listView_showAddViewHandler(event)"
showModifyView
="listView_showModifyViewHandler(event)"
showPreviewView
="listView_showPreviewViewHandler(event)"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="修改" icon="@Embed(source='http://www.cnblogs.com/http://www.cnblogs.com/__assets/icon/main/36/modify.png')">
<view:CommodityModifyView id="modifyView" width="100%" height="100%" commodityVO="{this.vo}" returnToListView="addView_returnToListViewHandler(event)" modifyOK="modifyView_modifyOKHandler(event)"/>
</s:NavigatorContent>
<s:NavigatorContent id="AddContent" width="100%" height="100%" label="新增" icon="@Embed(source='http://www.cnblogs.com/http://www.cnblogs.com/__assets/icon/main/36/add.png')">
<view:CommodityAddView id="addView" width="100%" height="100%" returnToListView="addView_returnToListViewHandler(event)" addOK="addView_addOKHandler(event)"/>
</s:NavigatorContent>
</mx:ViewStack>

我想刷新新增view 给NavigatorContent指定一个ID:AddContent

创建ViewStack的change事件(当所选的子容器更改时分派此方法)

代码

            protected function viewStack1_changeHandler(event:IndexChangedEvent):void
{
// TODO Auto-generated method stub
var nav:NavigatorContent = event.relatedObject as NavigatorContent;
if(nav.id == "AddContent")
{
addView = new CommodityAddView();

nav.addElement(addView);
}
else
{
AddContent.removeElement(addView);
nav= null;
}
}



 

你可能感兴趣的:(stack)