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

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

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

    我的漫漫程序之旅

    專注于JavaWeb開發
    隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
    數據加載中……

    基于jsTree的無限級樹JSON數據的轉換

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

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

    }
    );

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

    $("#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" } 
        ]
      }

    }
    );


    這里需要一個從后臺實例集合轉換為它規定的json數據的形式.

    /**
         * 無限遞歸獲得jsTree的json字串
         * 
         * 
    @param parentId
         *            父權限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);
                
    // 有子節點
                if (a.getIshaschild() == 1)
                
    {
                    str 
    += "{attributes:{id:\"" + a.getAnid()
                            + "\"}
    ,state:\"open\",data:\"" + a.getAnname() + "\" ,";
                    str += "children:[";
                    
    // 查出它的子節點
                    List<Action> list = actionManager.queryByParentId(a.getAnid());
                    
    // 遍歷它的子節點
                    for (int j = 0; j < list.size(); j++)
                    
    {
                        Action ac 
    = list.get(j);
                        
    //還有子節點(遞歸調用)
                        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;
        }

    調用:
    @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是菜單類或權限類等的實體。
    效果圖:



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

    評論

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

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

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    @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數據的轉換  回復  更多評論   

    $("#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數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    @陽衡鋒
    請確認已經導入了
    <script type="text/javascript" src="path-to-jsTree/_lib.js"></script>

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    沒,我用<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>就報錯了。我發郵件給jstree的作者,他要我去下載最新版,下載下來的還是一樣。不知道最新的版本時候解決了這個問題。
    2009-05-07 12:47 | 陽衡鋒

    # re: 基于jsTree的無限級樹JSON數據的轉換[未登錄]  回復  更多評論   

    能不能把右鍵菜單給取消?
    2009-09-07 21:37 |

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    @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數據的轉換  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    json轉換為json樹形數據,怎么寫啊,其中字段里有兩個節點,一個是ID,一個是parentID,怎么樹形顯示啊?
    2014-03-04 15:20 | @fei

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    {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數據的轉換  回復  更多評論   

    : "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數據的轉換  回復  更多評論   

    : "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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    { 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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    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數據的轉換  回復  更多評論   

    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  回復  更多評論   

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

    # re: 基于jsTree的無限級樹JSON數據的轉換  回復  更多評論   

    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/

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


    網站導航:
     
    主站蜘蛛池模板: 粉色视频成年免费人15次| 久久久国产精品福利免费| aa级女人大片喷水视频免费| 大地资源在线观看免费高清| 亚洲AV日韩精品久久久久久久| 另类专区另类专区亚洲| 亚洲日韩激情无码一区| 特级毛片aaaa级毛片免费| 国产精品四虎在线观看免费 | 亚欧洲精品在线视频免费观看| 久久WWW免费人成人片| 日本高清不卡中文字幕免费| 日韩精品电影一区亚洲| 亚洲日韩一区二区一无码| 永久免费在线观看视频| 久久亚洲精品中文字幕三区| WWW免费视频在线观看播放| www.亚洲日本| 操美女视频免费网站| 亚洲狠狠成人综合网| 国产精品免费播放| 午夜免费福利视频| 亚洲第一精品福利| 国产亚洲福利一区二区免费看| 美女裸体无遮挡免费视频网站| 亚洲精品无码久久毛片波多野吉衣| 国产2021精品视频免费播放| 亚洲人成在线中文字幕| 日韩电影免费在线| 一级毛片免费播放视频| 亚洲av成人无码久久精品 | 亚洲日产2021三区在线| 欧美三级在线电影免费| 日韩免费电影网址| avtt天堂网手机版亚洲| 国产无遮挡又黄又爽免费视频 | 中文字幕乱码免费视频| 亚洲 日韩经典 中文字幕 | 亚洲毛片αv无线播放一区| 全黄a免费一级毛片人人爱| 中文字幕免费在线看线人动作大片 |