EXTJS4 Learning (vii) the store in MVC

Source: Internet
Author: User
Tags unique id

Ext.data.Store is the standard middleware used for data exchange and data interaction in ExtJS, whether it is a grid or a ComboBox, through which data reading, type conversion, sorting, paging, and searching are performed.

Ext.define (' User ', {    extend: ' Ext.data.Model ', fields    : [        {name: ' LoginName ', type: ' String '},        {name: ' IP ',  type: ' String '}    ]});

The store can read data from a local array, read data remotely from the server, and, of course, be able to read from the server proxy, all of which are implemented by proxy, and what are the distinctions, and how the implementation will be explained in the next section

To better understand how the store is used, let's do the following example

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//configured this to indicate that the dataset is actively loading}) ;
Some regular usage

Load Data store.load ();//Add Data Store.add ({loginname: ' administrator.com ', IP: ' 192.168.1.8 '});//Read Data Store.each (function (record) {Console.info (Record.get (' loginname ')); alert (Record.get (' loginname '));}); /Filter//store.filter ("LoginName",/\.com$/); Filter by a single domain (field): Store.filter ([              {property: ' LoginName ', Value:/\.com $/},              {filterfn:function (item) {return item.get ("IP") = = ' 192.168.1.5 ';}]); /Find a record of var record = Store.find (' LoginName ', ' guest ');//Get a quick Method for the first record in the store. var record = Store.first ();// Gets the record at the specified index var record = Store.getat (2);//Get the number of records in store var count = store.getcount;//Quick way to get the last record in the store var record = Store.last ();

Background Read data

var store = ext.create (' Ext.data.Store ', {    model: ' User ',    pagesize:5,//shows the number of bars per page, default    proxy: {        type: ' Ajax ',        URL: ' jsonserver.jsp ',        reader: {            type: ' json ',            root: ' Rows ',            totalproperty: ' Total '        },        Writer: {type: ' JSON '}}}    );

How to get Data

Store.load ({scope:this,    callback:function (Records, operation, success) {    //Get the total number of records    //console.info ( Store.getcount ()); This is derived from the statistical    Console.info (Store.gettotalcount ()) of the records;//This comes from the background of total    //Get the current page    Console.info (store.currentpage);    Ext.each (Records,function (record) {    console.info (record.get (' LoginName ');})})    ; /Show second page data store.loadpage (2);//Display previous page Data store.previouspage ();//Display next page Data store.nextpage ();

Background data, I provide in the form of JSP

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%><%string[] persons = new STRING[10];p ersons[0] =" {loginname: ' Tom ', IP: ' 19 2.168.1.1 '} ";p ersons[1] =" {loginname: ' Jack ', IP: ' 192.168.1.2 '} ";p ersons[2] =" {loginname: ' Mary ', IP: ' 192.168.1. 3 '} ";p ersons[3] =" {loginname: ' jone ', IP: ' 192.168.1.4 '} ";p ersons[4] =" {loginname: ' ada ', IP: ' 192.168.1.5 '} ";p ers  ONS[5] = "{loginname: ' Alex ', IP: ' 192.168.1.6 '}";p ersons[6] = "{loginname: ' Lucy ', IP: ' 192.168.1.7 '}";p ersons[7] = "{loginname: ' JMS ', IP: ' 192.168.1.8 '}";p ersons[8] = "{loginname: ' Smile ', IP: ' 192.168.1.9 '}";p ersons[9] = "{Login Name: ' Somnus ', IP: ' 192.168.1.10 '} ", int pageSize = Integer.parseint (request.getparameter (" page "). toString ()); int Limit = Integer.parseint (Request.getparameter ("Limit"). ToString ()); System.out.println ("pagesize=" +pagesize+ "limit=" +limit); StringBuffer personname = new StringBuffer ();p ersonname.append ("{");p ersonname.append ("Total:10, ");p ersonname.append (" Rows: ["); int min = (pageSize-1) *limit;int max = Pagesize*limit;if (Max >) {max = 10;} for (int i = min; i < Max; i++) {personname.append (persons[i]), if (I < max-1) {personname.append (",");}}; Personname.append ("]");p ersonname.append ("}"); Response.getwriter (). Write (Personname.tostring ());%>


Finally, an attribute of a store is introduced: storeId

The unique ID of the current store object. When this value is present, the current store will be registered in Ext.data.StoreManager so that it can be easily created elsewhere.

How to get

var store = Ext.data.StoreManager.lookup (' Simpsonsstore ')


EXTJS4 Learning (vii) the store in MVC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.