[Java] 异步 tree →→→→→进入此内容的聊天室

来自 , 2019-09-18, 写在 Java, 查看 124 次.
URL http://www.code666.cn/view/0c0a7566
  1. Service层:
  2. @Service
  3. public class ItemCatServiceImpl implements ItemCatService {
  4.  
  5.         @Autowired
  6.         private TbItemCatMapper itemCatMapper;
  7.        
  8.         @Override
  9.         public List<EasyUITreeNode> getItemCatList(long parentId) {
  10.                 // 根据parentId查询分类列表
  11.                 TbItemCatExample example = new TbItemCatExample();
  12.                 //设置查询条件
  13.                 Criteria criteria = example.createCriteria();
  14.                 criteria.andParentIdEqualTo(parentId);
  15.                 //执行查询
  16.                 List<TbItemCat> list = itemCatMapper.selectByExample(example);
  17.                 //转换成EasyUITreeNode列表
  18.                 List<EasyUITreeNode> resultList = new ArrayList<>();
  19.                 for (TbItemCat tbItemCat : list) {
  20.                         //创建一个节点对象
  21.                         EasyUITreeNode node = new EasyUITreeNode();
  22.                         node.setId(tbItemCat.getId());
  23.                         node.setText(tbItemCat.getName());
  24.                         node.setState(tbItemCat.getIsParent()?"closed":"open");
  25.                         //添加到列表中
  26.                         resultList.add(node);
  27.                 }
  28.                 return resultList;
  29.         }
  30.  
  31. }
  32.  
  33.  
  34. Controller层:
  35. @Controller
  36. @RequestMapping("/item/cat")
  37. public class ItemCatController {
  38.  
  39.         @Autowired
  40.         private ItemCatService itemCatService;
  41.        
  42.         @RequestMapping("/list")
  43.         @ResponseBody
  44.         public List<EasyUITreeNode> getItemCatList(@RequestParam(value="id", defaultValue="0")Long parentId) {
  45.                 List<EasyUITreeNode> list = itemCatService.getItemCatList(parentId);
  46.                 return list;
  47.         }
  48.        
  49. }
  50.  
  51. JS:显示异步tree:
  52.   initItemCat : function(data){
  53.         $(".selectItemCat").each(function(i,e){
  54.                 var _ele = $(e);
  55.                 if(data && data.cid){
  56.                         _ele.after("<span style='margin-left:10px;'>"+data.cid+"</span>");
  57.                 }else{
  58.                         _ele.after("<span style='margin-left:10px;'></span>");
  59.                 }
  60.                 _ele.unbind('click').click(function(){
  61.                         $("<div>").css({padding:"5px"}).html("<ul>")
  62.                         .window({
  63.                                 width:'500',
  64.                             height:"450",
  65.                             modal:true,
  66.                             closed:true,
  67.                             iconCls:'icon-save',
  68.                             title:'选择类目',
  69.                             onOpen : function(){
  70.                                 var _win = this;
  71.                                 $("ul",_win).tree({
  72.                                         url:'/item/cat/list',
  73.                                         animate:true,
  74.                                         onClick : function(node){
  75.                                                 if($(this).tree("isLeaf",node.target)){
  76.                                                         // 填写到cid中
  77.                                                         _ele.parent().find("[name=cid]").val(node.id);
  78.                                                         _ele.next().text(node.text).attr("cid",node.id);
  79.                                                         $(_win).window('close');
  80.                                                         if(data && data.fun){
  81.                                                                 data.fun.call(this,node);
  82.                                                         }
  83.                                                 }
  84.                                         }
  85.                                 });
  86.                             },
  87.                             onClose : function(){
  88.                                 $(this).window("destroy");
  89.                             }
  90.                         }).window('open');
  91.                 });
  92.         });
  93.     },
  94.  
  95. jsp:
  96. <a href="javascript:void(0)" class="easyui-linkbutton selectItemCat">选择类目</a>

回复 "异步 tree"

这儿你可以回复上面这条便签

captcha