/**
* 通过继承方式,设置reader writer
* 也可通过override重写/覆盖Ajax类实现
* 使用方式:
*
Ext.define('MyApp.store.xxx', {
extend: 'Ext.data.Store',
alias: 'store.xxx',
model: 'MyApp.model.xxx',
// 或proxy : 'api'
proxy: {
type: 'api', // proxy的alias为proxy.api
url: '~api/search/results'
}
});
后端返回json字符串格式:
{
success: true/false,
msg:'',
data:[],
total: 0
}
*/
Ext.define('tp.proxy.Api', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.api',
timeout: 60000, // default 30000(30 SECONDS)
pageParam: 'pageNum',
startParam: 'start',
limitParam: 'pageSize', // ~url?page=xx&start=xx&limit=xx
sortParam: 'sort',
filterParam: 'filter',
idParam: 'id',
batchOrder: 'destroy,create,update',
actionMethods : {create : "POST",read : "GET",update : "PUT",destroy : "DELETE"},
reader: {
type: 'json',
rootProperty: 'data',
successProperty: 'success',
totalProperty: 'total',
messageProperty: 'message'
},
writer: {
type: 'json',
encode: true, // true 表示以HTTP变量方式提交 ?xx=xx&xx=xx false表示流的方式
rootProperty:'data',
allowSingle: false, // true 表示允许提交单个记录,后端需对单/多做不同实现 false 统一用list、array接受处理
writeAllFields:true // true 表示只提交修改的字段 false表示全部提交
}
/*
sorters: [
{
property: 'name',
direction: 'ASC'
},
{
property: 'age',
direction: 'DESC'
}
],
filters: [
{
property: 'eyeColor',
value: 'brown'
}
]
// ~url?sort=[{"property":"name","direction":"ASC"},{"property":"age","direction":"DESC"}]&filter=[{"property":"eyeColor","value":"brown"}]
*/
});