ExtJs4學習MVC中的Store

來源:互聯網
上載者:User

ExtJs4學習MVC中的Store

Ext.data.Store是extjs中用來進行資料交換和資料互動的標準中介軟體,無論是Grid還是ComboBox,都是通過它 實現資料讀取、類型轉換、排序分頁和搜尋等操作的。

 

Ext.define('User', {    extend: 'Ext.data.Model',    fields: [        {name: 'loginname', type: 'string'},        {name: 'ip',  type: 'string'}    ]});

Store既可以從本地數組中讀取資料,也可以從伺服器遠程讀取資料,當然還可以伺服器代理讀取,這些都得靠proxy實現,至於還有哪些區分,以及實現方式將再下一節闡述

 

為了更好的說清楚Store的用法,我們做如下例子

 

var store = Ext.create('Ext.data.Store', {    model: 'User',    proxy: {        type: 'memory',        data:[{loginname:'admin',ip:'192.168.1.2'},{loginname:'guest',ip:'192.168.1.5'}]    },    //autoLoad:true//配置了此項,表明資料集自動載入});
一些常用方法

 

 

//載入資料store.load();//添加資料store.add({loginname:'administrator.com',ip:'192.168.1.8'});//讀取資料store.each(function(record){console.info(record.get('loginname'));alert(record.get('loginname'));});//過濾//store.filter("loginname", /\.com$/);根據單個屬性域(field)過濾:store.filter([              {property: "loginname", value: /\.com$/},              {filterFn: function(item) { return item.get("ip") == '192.168.1.5'; }}]);//尋找某條記錄var record = store.find('loginname','guest');//擷取store中第一條記錄的快捷方法.var record = store.first();//擷取指定index處的記錄var record = store.getAt(2);//擷取store中記錄的數量var count = store.getCount;//擷取store中最後一條記錄的快捷方法var record = store.last();



 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.