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;

    }
    
}


發佈了56 篇原創文章 · 獲贊 14 · 訪問量 41萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章