【ExtJS】Ext.data.JsonStore

  1. <span style="font-size:14px;">Ext.data.JsonStore  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />  
  6. <script type="text/javascript" src="adapter/ext/ext-base.js"></script>  
  7. <script type="text/javascript" src="ext-all.js"></script>  
  8. <script>  
  9. Ext.onReady(function(){  
  10.     // NOTE: This is an example showing simple state management. During development,  
  11.     // it is generally best to disable state management as dynamically-generated ids  
  12.     // can change across page loads, leading to unpredictable results.  The developer  
  13.     // should ensure that stable state ids are set for stateful components in real apps.  
  14.     Ext.state.Manager.setProvider(new Ext.state.CookieProvider());  
  15.  var store=new Ext.data.JsonStore({   
  16.     
  17.     //results 表示结果数  
  18.     //rows 表示从后台传过来的JSON数据  
  19.     data:{ "results": 2, "rows":[  
  20.         {"id":1, "city": "suzhou", "areacode": "0512", "perincome": "2500" },  
  21.         {"id":2, "city": "nanjing", "areacode": "025", "perincome": "2200" }]},  
  22.        //自动加载(不能用store.load())  
  23.     autoLoad:true,  
  24.     totalProperty:"results",  
  25.     root:"rows",  
  26.     fields:['title',  {name:'city',mapping:'city'},  
  27.     {name:'areacode',type:'int'},  
  28.     {name:'perincome',mapping:'perincome',type:'int'},  
  29.     {name:'id',mapping:'id',type:'int'}  
  30.     ]  
  31.   });  
  32.      
  33.     // create the Grid  
  34.     var grid = new Ext.grid.GridPanel({  
  35.         store: store,  
  36.         columns: [  
  37.            {id:'city',header: "city", width: 400, sortable: true, dataIndex: 'city'},  
  38.             {header: "areacode", width: 200, sortable: true, dataIndex: 'areacode'},  
  39.             {header: "perincome", width: 200, sortable: true, dataIndex: 'perincome'}  
  40.         ],  
  41.         stripeRows: true,  
  42.         autoExpandColumn: 'city',  
  43.         height:280,  
  44.         width:600,  
  45.         title:'Array Grid'  
  46.    });  
  47.  grid.on('rowclick', function(grid, rowIndex, e) {  
  48.        var recordr = store.getAt(rowIndex);  
  49.        alert('id is ' + recordr.get('id') + ',city name is ' + recordr.get('city'));  
  50.       // window.open('index.html');//设置转向地址,用于对row的操作,举个例子 当然也可以用location.href等  
  51.      });    
  52.  //把此grid放进grid-example里面  
  53.     grid.render('grid-example');  
  54. });  
  55. </script>  
  56. <div id="grid-example"></div>   
  57. </html></span>  

猜你喜欢

转载自sun80264629.iteye.com/blog/2357254