dojo Memory tree

jsp页面:

<div class="contentline listtree">
                            <div id="tree_container">&#160;</div>
                            <div id="div1">&#160;</div>
                        </div>

<script type="text/javascript">

require(["dojo/request","dojo/dom","dojo/store/Memory","dijit/tree/ObjectStoreModel","dijit/Tree"],function(request,dom,Memory,ObjectStoreModel,Tree){
    request.get("http://localhost:8080/irmp-web/web/test/showAllFunction.htm",{
        handleAs: "json"
    }).then(function(data){
        //alert(data);
          var myStore = new Memory({
            data:[{id: "root", children: data}],
            getChildren: function(object){
                return object.children;
            }
            
        });
        var myModel = new ObjectStoreModel({
            store: myStore, query: {id: 'root'},
            mayHaveChildren: function(objectt){
                //alert(objectt);
                if(objectt.children.length>0){
                    return true;
                }
                return false;
            }
        });
        var tree = new Tree({
            model: myModel,
            onClick: function(item){
                var url = item["url"];
                if(url != ""){                    
                    url = '${pageContext.request.contextPath}' + url + '?funcId=' + item["id"];    
                    window.location.href = url;
                }
            },
            showRoot:false
            },dom.byId("div1"));
       // tree.placeAt(win.body());
        tree.startup();
    });
 

    });

</script>

TreeController类:

package com.ibm.banking.irmp.web;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.ibm.banking.auth.function.Function;
import com.ibm.banking.auth.function.FunctionService;
import com.ibm.banking.framework.web.view.GsonView;
import com.ibm.banking.irmp.index.indicator.IndicatorService;
@Controller
@RequestMapping("/web/test")
public class TreeController{
    Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    FunctionService functionService;
    @Autowired
    IndicatorService indicatorService;
    ExclusionStrategy exclusionStrategy = new ExclusionStrategy() {

        public boolean shouldSkipField(FieldAttributes field) {
            String fieldName = field.getName();
            if (fieldName.equals("id") || fieldName.equals("name")|| fieldName.equals("children")|| fieldName.equals("url")) {
                return false;
            }
            return true;
            //return true;
        }

        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    };
    

    /**
     * 同步获取所有指标 ,使用异步获取指标的方式替代
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/showAllFunction")
    public GsonView showAllFunction(Model model) {
        
        List<Function> funs = functionService.getFunctionTree();

        model.addAttribute("funs", funs);

        //GsonView view = new GsonView("allcategories", null);
        
        GsonView view= new GsonView("funs", exclusionStrategy);

        return view;

    }
    
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值