乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      jquery EasyUI 異步樹(shù) treeview,我所做的真正意義上的異步樹(shù)(單選)

       賈朋亮博客 2014-05-13

      首先,寫(xiě)這篇文章的目的,在于幫助更多人更加輕松地實(shí)現(xiàn)客戶端Treeview,程序員的時(shí)間是寶貴的,在客戶端,你可能只需要幾行代碼就能完全搞定這棵樹(shù)。

      EasyUI易用靈活,但可惜說(shuō)明文檔太簡(jiǎn)單,網(wǎng)上不少的一些所謂異步樹(shù),名為異步,實(shí)則是一次性加載了全部的樹(shù)內(nèi)容,這樣在構(gòu)建一棵比較大的樹(shù)的時(shí)候,可能會(huì)造成效率上的嚴(yán)重影響.

          我們的目標(biāo),一般是:點(diǎn)擊某節(jié)點(diǎn)前的"展開(kāi)"圖標(biāo)====加載該節(jié)點(diǎn)下的子節(jié)點(diǎn)====下次展開(kāi),不用加載,直接展開(kāi);點(diǎn)擊節(jié)點(diǎn)的文字,選定內(nèi)容,做我們所要做的事情.效果如下圖:

          于是行動(dòng)開(kāi)始,首先,我們要加載EasyUI的核心文件及資源文件,HTML具體代碼如下---

       

      復(fù)制代碼
       1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
       2 
       3 <html xmlns="http://www./1999/xhtml" >
       4 <head runat="server">
       5     <title>Untitled Page</title>
       6     <link rel="stylesheet" href="easyui/themes/default/easyui.css" />
       7  <link rel="stylesheet" href="easyui/themes/icon.css" />
       8  <script type="text/javascript" src="easyui/jquery-1.4.2.min.js"></script>
       9     <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
      10     <script type="text/javascript">   
      11 
      12     $(function(){
      13             $('#tt2').tree({   
      14                 checkbox: false,   
      15                 url: '/common/GetGoupJsonByPid.ashx?pid=0',   
      16                 onBeforeExpand:function(node,param){
      17                     $('#tt2').tree('options').url = "/common/GetGoupJsonByPid.ashx?pid=" + node.id;// change the url                       
      18                     //param.myattr = 'test';    // or change request parameter
      19                 },               
      20                 onClick:function(node){             
      21                     alert(node.id); 
      22                 }   
      23             });   
      24         }); 
      25     </script>
      26 </head>
      27 <body>
      28     <form id="form1" runat="server">
      29     <div style="width:150px;">
      30         <ul id="tt2">
      31         </ul>
      32     </div>
      33     </form>
      34 </body>
      35 </html>
      復(fù)制代碼

       

       大家可以看到,這個(gè)代碼已經(jīng)是相當(dāng)簡(jiǎn)單了,然后, 我們要做的是服務(wù)器端的代碼返回工作,其實(shí)也很簡(jiǎn)單,核心代碼如下:

       

      復(fù)制代碼
       1             int parentId = -1;//默認(rèn)為-1,如果請(qǐng)求參數(shù)不正確,將不返回任何值
       2             string resultStr = string.Empty;
       3             if (!string.IsNullOrEmpty(context.Request.QueryString["pid"]))
       4             {
       5                 Int32.TryParse(context.Request.QueryString["pid"], out parentId);
       6             }
       7             if (parentId >= 0)
       8             {
       9 ........//此處省略得到數(shù)據(jù)列表的代碼
      10                     resultStr = "";
      11                     resultStr += "[";
      12                     foreach (數(shù)據(jù)類(lèi) item in 數(shù)據(jù)集List<>)
      13                     {
      14                         resultStr += "{";
      15                         resultStr += string.Format("\"id\": \"{0}\", \"text\": \"{1}\", \"iconCls\": \"icon-ok\", \"state\": \"closed\"", item.Id.ToString(), item.TxtName);
      16                         resultStr += "},";
      17                     }
      18                     resultStr = resultStr.Substring(0, resultStr.Length - 1);                   
      19                     resultStr += "]";
      20             }
      21 
      22 
      23             //最后返回json數(shù)據(jù)
      24             context.Response.Write(resultStr);
      25             
      復(fù)制代碼

       

       

      請(qǐng)注意,以上的服務(wù)器端代碼,請(qǐng)根據(jù)具體數(shù)據(jù)結(jié)構(gòu)情況進(jìn)行修改.

       

      好了,這樣,我們的工作就完成了.是不是很簡(jiǎn)單(另一個(gè)更簡(jiǎn)單,更好的Tree插件jquery.simple.tree).具體實(shí)現(xiàn)中,還可以根據(jù)情況進(jìn)行多選的設(shè)置.

      EasyUI代碼下載"http://jquery-easyui./download",我這里用的版本是1.2

      如果哪位兄弟用了覺(jué)得OK,可以留言,我們一起探討.

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類(lèi)似文章 更多