Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of Proxy in Ext.js

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what is the use of Proxy in Ext.js. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

One: description

Proxy is used by Store to load and save data. The types of Proxy are mainly divided into two types: client agent and server agent.

Client agent:

1.LocalStorageProxy: store data locally when supported by browsers

2.SessionStorageProxy: store data to session with browser support

3.MemoryProxy: data is stored in local memory and will be lost when the page is refreshed

Server agent:

1.Ajax: in the same domain, send the request to the server.

2.JsonP: send a request to the server in the case of cross-domain

3.Rest: request using RESTful HTTP

4.Direct: sends a request using Ext.direct.Manager.

Two: Ext.data.proxy.Ajax

AjaxProxy is one of the most widely used proxy methods in applications, which requests the server through ajax and loads data.

Such as:

Ext.define ('User', {

Extend: 'Ext.data.Model'

Fields: ['id',' name', 'email']

});

Var store = Ext.create ('Ext.data.Store', {

Model: 'User'

Proxy: {

Type: 'ajax'

Url: 'users.json'

}

});

Store.load ()

Here we load User data into Store. We define a Model in advance and expect the server to return the data of the corresponding field.

Next, we automatically generate a sotre through the configuration of proxy.

New Ext.data.proxy.Ajax ({

Url: 'users.json'

Model: 'User'

Reader: 'json'

});

1. Readers and Writers

AjaxProxy can configure a Reader to parse the information returned by the server. If Reader,AjaxProxy is not set

By default, a JsonReader.

Such as:

Var proxy = new Ext.data.proxy.Ajax ({

Model: 'User'

Reader: {

Type: 'xml'

Root: 'users'

}

});

Proxy.getReader (); / / returns an XmlReader instance based on the config we supplied

2.Url generation

AjaxProxy automatically inserts sorting, filtering, paging, and grouping options into any requested url, which he configures with the following parameters:

PageParam: page number (also refer to startParam and limitParam)

SortParam: sorting in

GroupParam: grouping

FilterParam: filterin

Three: config

1.extraParams: other parameters

2.limitParams: default is limit

3.noCache: whether to cache requests. Default is true.

4.pageParam: default is page

5.reader: Ext.data.reader.Reader

Used to parse data to a Model or a Store.

Such as:

Ext.create ('Ext.data.Store', {

Model: 'User'

Proxy: {

Type: 'ajax'

Url: 'users.json'

Reader: {

Type: 'json'

Root: 'users'

}

}

});

The Json string is:

{

"success": true

"users": [

{"name": "User 1"}

{"name": "User 2"}

]

}

6.url

7.actionMethods

Default value: create: 'POST', read:' GET', update: 'POST', destroy:' POST'

Four: Store & AjaxProxy examples

Var store = Ext.create ('MyDesktop.ext.TimeoutController', {

Fields: ['roleId',' roleName', 'status']

Proxy: {

Type: 'ajax'

ActionMethods: {

Read: 'POST'

}

PageParam: 'pageNo'

LimitParam: 'pageSize'

Url:'.. / role/findFuncRoles.do'

Reader: {

Type: 'json'

Root: 'funcRoles'

TotalProperty: 'totalCount'

}

}

});

This is the end of this article on "what is the use of Proxy in Ext.js?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report