Ext.js4 的Store携带参数加载中文,后台出现乱码解决办法


            pageSize: 50,
            autoLoad:true,
            autoDestroy: true,
            proxy: {
                type: 'ajax',
                url: F.url('/yoururl.do'),
                method: 'post',
                reader: {
                    type: 'json',
                    root: 'pageList.list',
                    idProperty: 'demandId',
                    totolProperty: 'pageList.page.total',
                    messageProperty: "msg"
                }
            },
            fields: fields

        });

在Ext.js中进行load()加载数据的时候,如果参数中携带了中文的话,提交到后台会出现参数值乱码的情况(而且乱码乱的我心里发毛,直接看不懂是那个国家的语言),而且提交方法也变成了get..

解决办法如下:

var store = Ext.create('Ext.data.Store', {
            storeId: 'benefitStore',
            pageSize: 50,
            autoLoad:true,
            autoDestroy: true,
            proxy: {
                type: 'ajax',
                url: F.url('/yoururl.do'),
                //method: 'post',
                actionMethods: {
                    read: 'POST'
                },
                reader: {
                    type: 'json',
                    root: 'pageList.list',
                    idProperty: 'demandId',
                    totolProperty: 'pageList.page.total',
                    messageProperty: "msg"
                }
            },
            fields: fields
        });


API 说明:

actionMethods : Object

Mapping of action name to HTTP request method. In the basic AjaxProxy these are set to 'GET' for 'read' actions and 'POST' for 'create', 'update' and 'destroy' actions. The Ext.data.proxy.Rest maps these to the correct RESTful methods.

Defaults to: {create: 'POST', read: 'GET', update: 'POST', destroy: 'POST'}

转载于:https://my.oschina.net/Rayn/blog/321085

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ext.data.Store 类是 ExtJS 中用于管理数据的核心类之一,它提供了从后台获取数据、本地缓存数据、数据筛选和排序等功能。下面介绍一下 Ext.data.Store后台获取数据的几种方式。 1. Ajax 请求方式 可以通过在 Store 的 proxy 配置中设置 type 为 ajax,然后配置 url、method、params 等参数来发送 Ajax 请求,从后台获取数据。示例代码如下: ``` Ext.create('Ext.data.Store', { proxy: { type: 'ajax', url: 'your_url', method: 'GET', params: { // 请求参数 }, reader: { type: 'json', rootProperty: 'data' } }, autoLoad: true, fields: [ // 字段定义 ] }); ``` 2. JsonP 请求方式 可以通过在 Store 的 proxy 配置中设置 type 为 jsonp,然后配置 url、callbackKey 等参数来发送 JsonP 请求,从后台获取数据。示例代码如下: ``` Ext.create('Ext.data.Store', { proxy: { type: 'jsonp', url: 'your_url', callbackKey: 'callback', reader: { type: 'json', rootProperty: 'data' } }, autoLoad: true, fields: [ // 字段定义 ] }); ``` 3. Restful 请求方式 可以通过在 Store 的 proxy 配置中设置 type 为 rest,然后配置 url、reader、writer 等参数来发送 Restful 请求,从后台获取数据。示例代码如下: ``` Ext.create('Ext.data.Store', { proxy: { type: 'rest', url: 'your_url', reader: { type: 'json', rootProperty: 'data' }, writer: { type: 'json' } }, autoLoad: true, fields: [ // 字段定义 ] }); ``` 4. WebSocket 请求方式 可以通过在 Store 的 proxy 配置中设置 type 为 websocket,然后配置 url、reader、writer 等参数来发送 WebSocket 请求,从后台获取数据。示例代码如下: ``` Ext.create('Ext.data.Store', { proxy: { type: 'websocket', url: 'your_url', reader: { type: 'json', rootProperty: 'data' }, writer: { type: 'json' } }, autoLoad: true, fields: [ // 字段定义 ] }); ``` 需要注意的是,以上不同类型的请求方式需要根据后台接口的实际情况进行选择和配置。同时,在 Store 的 fields 配置中也需要定义从后台获取的数据字段。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值