Extjs4 使用store的post方法

引用官网的一句话

  Now when we call store.load(), the AjaxProxy springs into action, making a request to the url we configured ('users.json' in this case). As we're performing a read, it sends a GET request to that url (see actionMethods to customize this - by default any kind of read will be sent as a GET request and any kind of write will be sent as a POST request).

我们点进去看看它源码:

Ext.define('Ext.data.proxy.Ajax', {
requires: ['Ext.Ajax'],
extend: 'Ext.data.proxy.Server',
alias: 'proxy.ajax',
alternateClassName: ['Ext.data.HttpProxy', 'Ext.data.AjaxProxy'], /**
* @property {Object} actionMethods
* 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 {@link Ext.data.proxy.Rest} maps these to the
* correct RESTful methods.
*/
actionMethods: {
create : 'POST',
read : 'GET',
update : 'POST',
destroy: 'POST'
}, // Keep a default copy of the action methods here. Ideally could just null
// out actionMethods and just check if it exists & has a property, otherwise
// fallback to the default. But at the moment it's defined as a public property,
// so we need to be able to maintain the ability to modify/access it.
defaultActionMethods: {
create : 'POST',
read : 'GET',
update : 'POST',
destroy: 'POST'
},
  ... ... ...
}

到这里,我想你的思路也很清晰了.具体做法如下


1.覆盖 actionmathods 方法:

Ext.define('Sencha.store.Users', {
extend: 'Ext.data.Store', config: {
model: 'Sencha.model.Users',
autoLoad: true,
proxy: {
type: 'ajax',
actionMethods: {
create : 'POST',
read : 'POST', // by default GET
update : 'POST',
destroy: 'POST'
},
url: 'teams.json'
}
}
});
var mystore = Ext.create('Ext.data.Store', {
// 分页大小
pageSize : 20,
model : 'mydata',
storeId : 'mystore',
proxy : {
type : 'ajax',
actionMethods : {
create : 'POST',
read : 'POST', // by default GET
update : 'POST',
destroy : 'POST'
},
url : mj.basePath + 'service/user!datagrid.cy',
reader : {
root : 'leafData',
totalProperty : 'totalRows'
}
},
sorters : [ {
property : 'createTime', // 排序字段
direction : 'desc'// 默认ASC
} ]
})

2. 覆盖 defaultActionMethods 方法:

var mystore = Ext.create('Ext.data.Store', {
// 分页大小
pageSize : 20,
model : 'mydata',
storeId : 'mystore',
proxy : {
type : 'ajax',
defaultActionMethods : {
create : 'POST',
read : 'POST', // by default GET
update : 'POST',
destroy : 'POST'
},
url : mj.basePath + 'service/user!datagrid.cy',
reader : {
root : 'leafData',
totalProperty : 'totalRows'
}
}

3. or define your own proxy class

Ext.define('Sencha.data.PostAjax', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.postproxy', // must to get string reference
config: {
actionMethods: {
create : 'POST',
read : 'POST', // by default GET
update : 'POST',
destroy: 'POST'
},
}
} Ext.define('Sencha.store.Teams', {
extend: 'Ext.data.Store', config: {
model: 'Sencha.model.Team',
autoLoad: true,
proxy: {
type: 'ajaxpost'
url: 'teams.json'
}
}
});

参考资料:  http://blog.csdn.net/henriezhang/article/details/8978919  

最新文章

  1. Java面试之SpringMVC总结以及在面试中的一些问题.
  2. CocoaPods 抛出[!] Unable to satisfy the following requirements: 错误
  3. Unicode 转成中文
  4. php面向对象常见的专业术语
  5. GitHub的三个按钮
  6. Java数据库ResultSet转json实现
  7. IOS 作业项目(4)步步完成 画图 程序(剧终)
  8. python time,string 转换
  9. 【ZZ】MySql语句大全:创建、授权、查询、修改等
  10. 中文乱码的分析 和 从Eclipse设置启动JVM时的字符集(转)
  11. varchar和Nvarchar的区别
  12. LLBL Gen Pro 5.0
  13. xmlplus 组件设计系列之七 - 路由
  14. PeopleRank
  15. Servlet中文乱码问题解决办法
  16. PHP XML 函数
  17. pillow的用法
  18. 1013. Battle Over Cities 用dfs计算联通分量
  19. C/C++ 控制台窗口暂停
  20. noip宝藏

热门文章

  1. 发布ASP.NET网站到IIS
  2. js中关于原型的几个方法
  3. Weex
  4. oledb 操作 excel
  5. UI2_视图切换ViewController
  6. 使用struct实现面向对象编程的封装
  7. 从基础知识到重写Spring的Bean工厂中学习java的工厂模式
  8. C# http下载(支持断点续传)
  9. 过滤字段中HTML标签
  10. mysql手工注入