flex动态tree

刚开始学习flex做一个动态tree的例子有如下步骤:

1.从数据库得到数据

2.用递归算法,使父子节点一一对应起来

3.通过map包装arraylist,
public ActionForward findAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws PioaGisException {

List userList = navBO.getNaVAll("0");
JSONArray jsonArr = new JSONArray();
for (int i=0;i<userList.size();i++) {
NodeBean nodeBean0 = (NodeBean)userList.get(i);
Map map= new HashMap();
if(nodeBean0.getChilds()!=null && nodeBean0.getChilds().size()>0){
ArrayList list1 = new ArrayList();
for(int j=0;j<nodeBean0.getChilds().size();j++){
Map map1= new HashMap();
NodeBean nodeBean1 = (NodeBean)nodeBean0.getChilds().get(j);
if(nodeBean1.getChilds()!=null && nodeBean1.getChilds().size()>0){
ArrayList list2 = new ArrayList();
for(int k=0;k<nodeBean1.getChilds().size();k++){
Map map2= new HashMap();
NodeBean nodeBean2 = (NodeBean)nodeBean1.getChilds().get(k);
//map2.put("id", nodeBean2.getId());
map2.put("label", nodeBean2.getNodeName());
list2.add(map2);
}
//map1.put("id",nodeBean1.getId());
map1.put("label", nodeBean1.getNodeName());
map1.put("children", list2);
list1.add(map1);
}else{
//map1.put("id", nodeBean1.getId());
map1.put("label", nodeBean1.getNodeName());
list1.add(map1);
}

}
//map.put("id", nodeBean0.getId());
map.put("label", nodeBean0.getNodeName());
map.put("children", list1);
}
jsonArr.put(map);
}
try {
String json = jsonArr.toString();
response.getWriter().write(json);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

由于多加了jsonObj.put("nav", jsonArr),在flex使用调用中总是显示OBJECT
花了我俩小时找问题

4.flex proxy获取数据,我的是HTTPService方式,如何使用网络上很多的,就不多说哦
var json:JSONDecoder=new JSONDecoder(event.result));
var array:Array=json.getValue() as Array;
var arrayCollection:ArrayCollection = new ArrayCollection(array);
data = arrayCollection;
sendNotification(TestFacade.GET_ALL_NAVIGATION_COMPLETE, data );

5.mxml显示
<mx:Canvas id="canvas1" label="Canvas 1" width="100%" height="622"
backgroundColor="#C1D60E">
<mx:Tree id="myTree" width="50%" labelFunction="myTreeLabel"
height="100%" dataProvider="{navData}"/>
</mx:Canvas>

public function myTreeLabel(item:Object):String{
return item.label;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值