当前位置 : 主页 > 网页制作 > Dojo >

dojo Memory tree

来源:互联网 收集:自由互联 发布时间:2021-06-15
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"],func

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;     }      }

网友评论