[轉]ExtJs中的Store

來源:互聯網
上載者:User

標籤:

store是一個儲存資料對象Model的集合緩衝,他可以為extjs的可視化組建提供資料(GridPanel,ComboBox)等

類結構

Ext.data.AbstractStore

       Ext.data.Store  沒有特殊情況這個類就可以滿日常的開發了

              Ext.data.ArrayStore

              Ext.data.DirectStore

              Ext.data.ArrayStore  內建輔助的類

              Ext.data.JsonStroe   內建輔助的類

       Ext.data.TreeStore

Ext.data.Store使用

       參數

        autoLoad(Boolean/Object) : 自動載入資料,自動調用load

        data(Array) : 內建資料對象的數組,初始化的是就要被裝在

        model(Model): 資料集合相關的模型

        fields(Field):欄位的集合,程式會自動產生對於的Model

       方法

        each( Function f, [Object scope] ) : void 變數資料中的Model

代碼舉例:

 

[javascript] view plaincopy 
  1. Ext.onReady(function(){  
  2. //定義了一個person的model  
  3. //     Ext.define("person",{  
  4. //       extend:"Ext.data.Model",  
  5. //       fields:[  
  6. //        {name:"name"},  
  7. //        {name:"age"}  
  8. //       ]  
  9. //     });  
  10. //建立了一個store資料集  
  11.      var s=new Ext.data.Store({  
  12.         //store可以自己定義fields,省略model  
  13.         fields:[  
  14.           {name:"name"},  
  15.           {name:"age"}  
  16.         ],  
  17.  //如果使用了代理以後,就可以省略store的data屬性了  
  18.         proxy:{  
  19.            type:"ajax",  
  20.            url:"person.jsp"  
  21.         }  
  22. //        data:[  
  23. //        {name:"hanhan313",age:23},  
  24. //        {name:"hanhan313",age:22}  
  25. //         ],  
  26.          //model:"person"  
  27.          //autoLoad:true  
  28.      });  
  29. //     s.each(function(model){  
  30. //       //Ext.Msg.alert("title",model.get("name"));  
  31. //     alert(model.get("name"));  
  32. //     });  
  33.      //除了自動載入,也可以手動載入,如果使用了代理的話應該使用手動載入,因為使用自動載入的話,在遍曆的使用資料還在非同步載入,沒有擷取到  
  34.      s.load(function(records,operation, success) {  
  35.          Ext.Array.each(records,function(model){  
  36.             alert(model.get("name"));  
  37.          });  
  38.      });  
  39. });  

 

person.jsp頁面:

 json格式的資料:

<%

    response.getWriter().write("[{name:‘hanhan313‘,age:26},{name:‘hahaha‘,age:34}]");

%>

[轉]ExtJs中的Store

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.