Flex Tree的刷新问题,求救求救!!
flex树的点击打开
//树的点击打开事件
protected function itemOpeningHandler(event:TreeEvent):void
{
selectedNode=event.item as SpecVO;
if(!specTree.isItemOpen(event.item)&&selectedNode.children.length==0)
{
// 此处通过Blazeds远程异步调用java端方法,获取数据
......
}
}
//通过Blazeds调用java端方法后flex端自动加载的方法,以此获取树节点的children,并刷新树
protected function remoteJavaData(event:ResultEvent):void
{
selectedNode.children=event.result as ArrayCollection;
treeData.itemUpdated(selectedNode);
}
<mx:Tree id="myTree" dataProvider="{treeData}"
itemOpening="itemOpeningHandler(event)" labelField="name" >
</mx:Tree>
其中treeData是一个ArrayCollection,其数据结果是从java端传过来的,如果通过在树上进行单机节点图标操作,树是可以打开的;现在我通过增加或删除某一节点,然后获取其父节点数据并指定给selectedNode,然后通过下列方法重新加载其children,这也是成功的,
protected function itemOpeningHandler(event:TreeEvent):void
{
selectedNode=event.item as SpecVO;
if(!specTree.isItemOpen(event.item)){
// 此处通过Blazeds远程异步调用java端方法,获取数据
......
}
只是在重新远程执行treeData.itemUpdated(selectedNode)时,树的数据没有刷新
寻求大家的帮助,谢谢!
[解决办法]
弄了一个小程序实现了下,没有出现楼主的问题---
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:tw="http://www.servasoftware.com/2009/twaver/flex"
applicationComplete="init()" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
private var cbDate:ArrayCollection = new ArrayCollection([
{label:'icon1',img:'3.png',name:'dfl'},
{label:'icon2',img:'4.png',name:'lzg'},
{label:'icon3',img:'ZoomIn.png',name:'dfl'},
{label:'icon4',img:'ZoomOut.png',name:'ddfl'}
]);
[Bindable]
private var addDAta:ArrayCollection=new ArrayCollection([
{label:'icon1',img:'3.png',name:'dfl'}]);
private function add():void{
var item:Object=tree.selectedItem ;
item.children=addDAta;
cbDate.itemUpdated(item);
}
]]>
</mx:Script>
<mx:Button label="add" />
<mx:Button label="cancel"/>
<mx:Tree id="tree" dataProvider="{cbDate}" click="add()"></mx:Tree>
</mx:Application>
[解决办法]
我用过json数据格式实现过树的动态加载,运行良好--
你的那个我在网上瞅了瞅,搜到了这个,希望能帮你一下http://www.cesclub.com/bw/jishuzhongxin/Webjishu/2011/1210/17467.html