隨筆-9  評(píng)論-168  文章-266  trackbacks-0

          (一)JS文件:  extjs.js

          Ext.onReady(function() {

            var fields=Ext.data.Record.create(
           [
          // 'title',
          //  {name : 'replycount',
          //    type : 'int'
          //   },
          //    {
          //    name : 'lastpost',
          //    mapping : 'lastpost',
          //    type : 'date',
          //    dateFormat : 'timestamp'
          //   }
          //   ]
          //'title','forumid','forumtitle']
             'title',//一種顯示方式,最簡(jiǎn)定義.
             {name: 'forumid'},//type:'int'},//二種顯示方式,可定義其它選項(xiàng)
             {name: 'forumtitle'}]//,mapping : 'lastpost',type:'date',dateFormat : 'timestamp'}]
             );
           
           // 表格數(shù)據(jù),proxy:從哪里獲得數(shù)據(jù),reader:如何解析這個(gè)數(shù)據(jù).
            var ds = new Ext.data.Store({
            // proxy : new Ext.data.HttpProxy( {url:'extjs-index.jsp'} ),
            proxy : new Ext.data.ScriptTagProxy({
             url : 'http://extjs.com/forum/topics-browse-remote.php'
            }),
            //JsonReader( Object meta ,    //行數(shù)據(jù)對(duì)象(行數(shù)據(jù)+記錄總數(shù))
               //            Object recordType )  //列數(shù)據(jù)對(duì)象
            reader : new Ext.data.JsonReader({
             root:'topics',                //數(shù)組類型的行對(duì)象
             totalProperty:'totalCount'  //記錄總數(shù)(可選)              
             },fields
             ),
            remoteSort : true
           });

           // create the data store
           // var ds = new Ext.data.SimpleStore({
           // fields: [
           // mapping只能賦值數(shù)字.錯(cuò)誤代碼:{name: 'id',mapping:'id'},
           // {name: 'id',mapping:0},
           // {name: 'name',mapping:1},
           // {name: 'descn',mapping:2}
           // ]
           // });
           // ds.loadData(myData);

           

            //表格列頭的定義,以下定義四列.
            //每列的header顯示GRID這列的名稱,dataIndex 與 json定義的鍵相對(duì)應(yīng)(可選,只要JsonReader定義時(shí)確定就行了).
               //此項(xiàng)定義GRID 與 JSON 列數(shù)據(jù)的關(guān)聯(lián).
           var colModel = new Ext.grid.ColumnModel([
            {header:'編號(hào)',dataIndex:'title'},
            {header:'名稱',dataIndex:'forumid'},
            {header:'descn',sortable: true,dataIndex:'forumtitle'}
            ]);

           // 裝配數(shù)據(jù).
           var grid = new Ext.grid.GridPanel({
            el : 'MyPageGrid', // 渲染位置的id,對(duì)應(yīng)的名字是el.
            store : ds,
            cm : colModel,
            // autoExpandColumn: 'OrderID', //引用已不存在的變量使剛才數(shù)據(jù)無(wú)法顯示.
            // renderTo: document.body,
            height : 350,
            width : 600,
            title : 'Array Grid', // 表格標(biāo)題.
            loadMask : {
             msg : '正在加載數(shù)據(jù),請(qǐng)稍侯……'
            }, // 數(shù)據(jù)讀入等待顯示界面.
            bbar : new Ext.PagingToolbar({ // 分頁(yè)欄定義.
             pageSize : 20,
             store : ds,
             displayInfo : true,
             displayMsg : '當(dāng)前顯示 {0} - {1}條記錄 /共 {2}條記錄',
             emptyMsg : "無(wú)顯示數(shù)據(jù)"
            })
           });
           // 顯示表格.
           grid.render();
           
           //讀入數(shù)據(jù)信息,放置位置決定其何時(shí)加載.如最后:表格顯示之后,在加載(必選項(xiàng)).
             ds.load({
              // 從第0個(gè)數(shù)據(jù)開(kāi)始.每頁(yè)9個(gè).
            params : {
             start : 0,
             limit : 9
            }
           });
          });

          (二)JSP文件: extjs.jsp

          <%@ page language="java" pageEncoding="UTF-8"%>

           


          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
           <head>


            <title>My JSF 'extjs.jsp' starting page</title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
           <link rel="stylesheet" type="text/css" href="styles.css">
           -->
            <link rel="stylesheet" type="text/css"
             href="resources/css/ext-all.css" />
            <script type="text/javascript" src="adapter/ext/ext-base.js"></script>
            <script type="text/javascript" src="ext-all.js"></script>
          <script type="text/javascript" src="extjs.js"></script>
           </head>

           <body>

           

            <div id="MyPageGrid"></div>

           

           </body>
          </html>

          posted on 2008-06-04 15:42 紫蝶∏飛揚(yáng)↗ 閱讀(3356) 評(píng)論(2)  編輯  收藏 所屬分類: EXTJS

          評(píng)論:
          # re: Extjs 訪問(wèn)后臺(tái)數(shù)據(jù)學(xué)習(xí)一. 2008-09-05 16:10 | 處理
          源碼還缺extjs-index.jsp這個(gè)后臺(tái)文件,博主可以貼出來(lái)嗎,先謝謝了  回復(fù)  更多評(píng)論
            
          # re: Extjs 訪問(wèn)后臺(tái)數(shù)據(jù)學(xué)習(xí)一. 2008-09-05 20:24 | 紫蝶∏飛揚(yáng)↗
          ...我采用的是EXTJS的后臺(tái).那一個(gè)注釋掉了.最近我正在開(kāi)發(fā)EXTJS+SPRING+HIBERNATE項(xiàng)目,到時(shí)候會(huì)帖出源碼的.  回復(fù)  更多評(píng)論
            
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(5)

          隨筆檔案(9)

          文章分類(339)

          文章檔案(265)

          最新隨筆

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 都江堰市| 崇信县| 美姑县| 南澳县| 新巴尔虎右旗| 新民市| 拉萨市| 务川| 长海县| 肇源县| 沅陵县| 富平县| 于田县| 巴楚县| 吉隆县| 柞水县| 乳源| 宁夏| 手游| 龙胜| 琼海市| 井冈山市| 公主岭市| 丰原市| 余庆县| 西华县| 红桥区| 安陆市| 长白| 荆州市| 新源县| 洪泽县| 高雄市| 延吉市| 隆安县| 湘西| 高雄县| 晋江市| 遂平县| 荔浦县| 商水县|