<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我的漫漫程序之旅

    專注于JavaWeb開發(fā)
    隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
    數(shù)據(jù)加載中……

    基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換

    jstree 主頁 :
    http://www.jstree.com/

    其中提供了一種從后臺取數(shù)據(jù)渲染成樹的形式:
     $("#mytree").tree({
          data  : 
    {
            type  : 
    "json",
            url : 
    "${ctx}/user/power!list.do"
          }

    }
    );

    對于url中返回的值必須是它定義的json數(shù)據(jù)形式:

    $("#demo2").tree({
      data  : 
    {
        type  : 
    "json",
        json  : [ 
          
    { attributes: { id : "pjson_1" }, state: "open", data: "Root node 1", children : [
            
    { attributes: { id : "pjson_2" }, data: { title : "Custom icon", icon : "../media/images/ok.png" } },
            
    { attributes: { id : "pjson_3" }, data: "Child node 2" },
            
    { attributes: { id : "pjson_4" }, data: "Some other child node" }
          ]}

          
    { attributes: { id : "pjson_5" }, data: "Root node 2" } 
        ]
      }

    }
    );


    這里需要一個從后臺實(shí)例集合轉(zhuǎn)換為它規(guī)定的json數(shù)據(jù)的形式.

    /**
         * 無限遞歸獲得jsTree的json字串
         * 
         * 
    @param parentId
         *            父權(quán)限id
         * 
    @return
         
    */

        
    private String getJson(long parentId)
        
    {
            
    // 把頂層的查出來
            List<Action> actions = actionManager.queryByParentId(parentId);
            
    for (int i = 0; i < actions.size(); i++)
            
    {
                Action a 
    = actions.get(i);
                
    // 有子節(jié)點(diǎn)
                if (a.getIshaschild() == 1)
                
    {
                    str 
    += "{attributes:{id:\"" + a.getAnid()
                            + "\"}
    ,state:\"open\",data:\"" + a.getAnname() + "\" ,";
                    str += "children:[";
                    
    // 查出它的子節(jié)點(diǎn)
                    List<Action> list = actionManager.queryByParentId(a.getAnid());
                    
    // 遍歷它的子節(jié)點(diǎn)
                    for (int j = 0; j < list.size(); j++)
                    
    {
                        Action ac 
    = list.get(j);
                        
    //還有子節(jié)點(diǎn)(遞歸調(diào)用)
                        if (ac.getIshaschild() == 1)
                        
    {
                            
    this.getJson(ac.getParentid());
                        }

                        
    else
                        
    {

                            str 
    += "{attributes:{id:\"" + ac.getAnid()
                                    + "\"}
    ,state:\"open\",data:\"" + ac.getAnname()
                                    
    + "\" " + "   }
    ";
                            if (j < list.size() - 1)
                            
    {
                                str 
    += ",";
                            }

                        }

                    }

                    str 
    += "]";
                    str 
    += "   }";
                    
    if (i < actions.size() - 1)
                    
    {
                        str 
    += ",";
                    }

                }
            }
            
    return str;
        }

    調(diào)用:
    @org.apache.struts2.convention.annotation.Action(results =
        
    { @Result(name = "success", location = "/main/user/action-list.jsp") })
        
    public String list()
        
    {
            String str 
    = "[";
            
    // 從根開始
            str += this.getJson(0);
            str 
    += "]";
            
    this.renderJson(str);
            
    return null;
        }

    其中Action是菜單類或權(quán)限類等的實(shí)體。
    效果圖:



    posted on 2009-05-05 17:09 々上善若水々 閱讀(17623) 評論(27)  編輯  收藏

    評論

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    exttree最好了!配合dwr ok
    2009-05-05 22:50 | 大羅卜

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    Action ac = list.get(j);
    //還有子節(jié)點(diǎn)(遞歸調(diào)用)
    if (ac.getIshaschild() == 1)
    {
    this.getJson(ac.getParentid());
    }
    else
    {

    help
    2009-05-05 23:56 | web tasar?m?

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    @org.apache.struts2.convention.annotation.Action(results =
    { @Result(name = "success", location = "/main/user/action-list.jsp") })
    public String list()
    {
    String str = "[";
    // 從根開始
    str += this.getJson(0);
    str += "]";
    this.renderJson(str);
    return null;
    }
    2009-05-05 23:56 | yuz estetigi

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    $("#demo2").tree({
    data : {
    type : "json",
    json : [
    { attributes: { id : "pjson_1" }, state: "open", data: "Root node 1", children : [
    { attributes: { id : "pjson_2" }, data: { title : "Custom icon", icon : "../media/images/ok.png" } },
    { attributes: { id : "pjson_3" }, data: "Child node 2" },
    { attributes: { id : "pjson_4" }, data: "Some other child node" }
    ]},
    { attributes: { id : "pjson_5" }, data: "Root node 2" }
    ]
    }
    });
    2009-05-05 23:57 | Burun Estetigi

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    這個樹真的很不錯, 還有內(nèi)置的右鍵菜單及事件調(diào)用. 比 xloadtree 好看.
    2009-05-06 09:28 | BeanSoft

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    不知道怎么回事,我用這個樹的時候,發(fā)現(xiàn)很多問題,最有意思的是,我用不壓縮的能用,用那個min版竟然報錯。
    2009-05-06 13:38 | 陽衡鋒

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    @陽衡鋒
    請確認(rèn)已經(jīng)導(dǎo)入了
    <script type="text/javascript" src="path-to-jsTree/_lib.js"></script>

    我用<script type="text/javascript" src="path-to-jsTree/tree_component.min.js"></script>試了下,在我的工程里沒發(fā)現(xiàn)問題.ff和ie均測試。 
    2009-05-07 08:26 | 々上善若水々

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    沒,我用<script type="text/javascript" src="path-to-jsTree/tree_component.min.js"></script>跑得好好的,換成
    <script type="text/javascript" src="path-to-jsTree/tree_component.min.js"></script>就報錯了。我發(fā)郵件給jstree的作者,他要我去下載最新版,下載下來的還是一樣。不知道最新的版本時候解決了這個問題。
    2009-05-07 12:47 | 陽衡鋒

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換[未登錄]  回復(fù)  更多評論   

    能不能把右鍵菜單給取消?
    2009-09-07 21:37 | 風(fēng)

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    @風(fēng)
    可以,請自行參考jstree api
    2009-09-09 13:37 | 々上善若水々

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    @陽衡鋒
    作者在最新版里提供的下載確實(shí)是報錯的,jquery.xslt.js這個插件不知道為什么被作者給換掉了,貌似也不是最新版的插件,在火狐下是好的,ie下解析xml是有問題的,你從插件的官方下載最新的替換就沒事了,或者用作者老版本的這個插件。
    2009-09-12 16:58 | 周萬峰

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    @org.apache.struts2.convention.annotation.Action(results =
    { @Result(name = "success", location = "/main/user/action-list.jsp") })
    public String list()
    {
    String str = "[";
    // 從根開始
    str += this.getJson(0);
    str += "]";
    this.renderJson(str);
    return null;
    }
    這個action 中 的 this.renderJson 引用那個類庫?
    2013-08-22 08:52 | javaWeb

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    sdaf
    2014-03-04 15:18 | @fei

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    json轉(zhuǎn)換為json樹形數(shù)據(jù),怎么寫啊,其中字段里有兩個節(jié)點(diǎn),一個是ID,一個是parentID,怎么樹形顯示啊?
    2014-03-04 15:20 | @fei

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    {ID: "pjson_2"}, Veri: {title: "Özel simge", simgesi: ".. / media / images / ok.png"}},
    {Özellikleri: {ID: "pjson_3"}, Veri: "Çocuk dü?üm 2"},
    {Özellikleri: {ID: "pjson_4"}, Veri: "Di?er Baz? Çocuk dü?üm"}
    ]},

    http://otomatikrentacar.com
    2014-06-24 03:24 | Otomatik Rent A Car

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    : "pjson_2"}, Veri: {title: "Özel simge", simgesi: ".. / media / images / ok.png"}},
    {Özellikleri: {ID: "pjson_3"}, Veri: "Çocuk dü?üm 2"},
    {Özellikleri: {ID: "pjson_4"}, Veri: "Di?er Baz? Çocuk
    http://ilkyazreklam.com
    2014-07-14 21:00 | ilkyaz reklam

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    : "pjson_2"}, Veri: {title: "Özel simge", simgesi: ".. / media / images / ok.png"}},
    {Özellikleri: {ID: "pjson_3"}, Veri: "Çocuk dü?üm 2"},
    {Özellikleri: {ID: "pjson_4"}, Veri: "Di?er Baz? Çocuk "}
    http://ilkyazreklam.com
    2014-07-14 21:01 | ilkyaz reklam

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    ukash bozdurma icin zel simge", simgesi: ".. / media / images / ok.png"}},
    {Özellikleri: {ID: "pjson_3"}, Veri: ") Result(name = "success", location = "/main/user/action-list.jsp") })
    public String list()
    {
    String str = "[";
    // 從根開始
    str += this.getJson(0);
    str += "]";
    this.renderJson
    2014-07-14 21:05 | ukash bozdurma

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    likleri: {ID: "pjson_3"}, Veri: ") Sonuç (name =" Ba?ar? ", Location =" / ana / kullan?c? / Aksiyon-list.jsp ")})
    Kamu Dize listesi ()
    {
    Dize str = "[";
    / / root gelen
    str + = this.getJson (0);
    str + = ""]; http://www.hepsiukash.com/p/ukash-bozdurma.html
    2014-07-14 21:06 | ukash bozdurma

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    Bahis, Poker, Casino, Rulet, Tavla, Batak, ?ddaa, Okey, Android Bahis, ?phone Bahis, Best10 CAsino, Bets10 Casino


    http://www.androidbahis.com/
    2014-07-15 09:33 | ahmet katar

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    { attributes: { id : "pjson_2" }, data: { title : "Custom icon", icon : "../media/images/ok.png" }

    + "\"},state:\"open\",data:\"" + a.getAnname() + "\" ,";

    { @Result(name = "success", location = "/main/user/action-list.jsp") })


    https://www.oddsring404.com/livecasino?wm=8308867
    2014-07-25 09:31 | OddsRing Giri?

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    Kilercio?lu evden eve nakliyat ?ehir içi ve ?ehirler aras? ta??mac?l?k için kurumsal web sayfam?z http://www.sehirlerarasievdenevetasimacilik.com.tr
    2014-08-05 01:42 | ?ehirleraras? nakliyat

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    kilercio?lu nakliyat e?ya depolama ofis ta??ma ve kurumsal ta??mac?l?k hizmetleri. http://www.istanbulizmirevdenevenakliye.com
    2014-08-05 01:44 | e?ya depolama

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    Kurumsal ta??mac?l?k i? yeri ta??ma ofis ta??mac?l??? ve evden eve nakliyat
    2014-08-05 01:46 | ofis ta??ma ?irketleri

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    ts2.convention.annotation.Action(results =
    { @Result(name = "success", location = "/main/user/action-list.jsp") })
    public String list()

    http://www.bozdurmak.com/
    2014-08-08 05:54 | ukash bozdurma

    #  re  回復(fù)  更多評論   

    額r熱r
    2014-08-22 15:52 | f'f

    # re: 基于jsTree的無限級樹JSON數(shù)據(jù)的轉(zhuǎn)換  回復(fù)  更多評論   

    d : "pjson_3" }, data: "Child node 2" },
    { attributes: { id : "pjson_4" }, data: "Some other child node" }
    ]},
    { attributes: { id : "pj
    2015-04-18 15:37 | https://iddaaoyunlari.com/

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲国产a级视频| 亚洲精品国精品久久99热一| 老司机午夜性生免费福利 | 成全视频在线观看免费| 亚洲黄色片在线观看| 中文字幕无码不卡免费视频 | 99re这里有免费视频精品 | 免费无码一区二区三区| 亚洲色大成网站www久久九| 国产日产亚洲系列| 99久久综合国产精品免费| 亚洲精品无码久久久久YW| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 13一14周岁毛片免费| 豆国产96在线|亚洲| 亚洲一区二区三区日本久久九| 午夜两性色视频免费网站| eeuss在线兵区免费观看| youjizz亚洲| 亚洲va无码手机在线电影| 女人与禽交视频免费看| 久久国产精品免费视频| 污污视频免费观看网站| 亚洲国产综合人成综合网站00| 久久久久久A亚洲欧洲AV冫| 67194成是人免费无码| 久久精品私人影院免费看| 免费亚洲视频在线观看| 亚洲一级黄色大片| 亚洲成av人在线视| 亚洲国产一区二区三区| 四虎影院在线免费播放| 88xx成人永久免费观看| 最近免费中文字幕中文高清| 亚洲av成人无码网站…| 国产色在线|亚洲| 亚洲视频在线不卡| 亚洲AV无码一区二区乱子伦| 亚洲成a人片在线观看老师| 免费高清av一区二区三区| 手机看黄av免费网址|