Extjs4.2 rest 与webapi数据交互
来源:互联网 发布:淘宝优惠券图片素材 编辑:程序博客网 时间:2024/04/27 17:37
这一章接着上一篇
对于Ext.data.Store 介紹 与总结,以及对以前代码的重构与优化
1.对于更新OnUpdate()函数的修改:先上代码:
function OnUpdate(record) { //获取要更新的数据 var functionCode = Ext.getCmp('code').getValue(); var FunctionName = Ext.getCmp('name').getValue(); var IsEnabled = Ext.getCmp('isEnable').getValue(); var Invoker = Ext.getCmp('Invoker').getValue(); var module = Ext.getCmp('Module').getValue(); record.set('FunctionCode', functionCode); record.set('FunctionName', FunctionName); record.set('IsEnabled', IsEnabled); record.set('Invoker', Invoker); record.set('Module', module); store.commitChanges(); win.close();}
这里面将要修改的record记录传了过来,直接使用record的set方法对数据进行更新,然后用store的commitChanges()方法进行提交。
然后它对应的就是rest的Put方式。
2.rest方式前面讲到都是向后台传值,那么他从后台传出来的值应该怎么办呢。其实细心的读者可能会发现,上面程序是存在问题的,啥问题?如果后台对数据的操作失败了怎么办?我怎么才能知道,这就是问题所在了。
在网上找了好久才找到方法,在store使用afterRequest,这个在api上没有,也不知道api不全或者其他原因,我试了好几种方法都不行,折腾了快一天了才搞定
大家看下代码:
store = Ext.create('Ext.data.Store', { autoLoad: true, autoSync: true, pageSize: 20, model: 'InterfaceModel', proxy: { type: 'rest', url: 'api/InterfaceManage', reader: { type: 'json', root: 'Data', totalProperty: 'TotolRecord', successProperty: 'success', messageProperty: 'msg' }, writer: { type: 'json' }, afterRequest: function (request, success) { var result = request.operation.success; if (request.action == 'read') { } else if (request.action == 'create') { if (result) { Ext.Msg.alert('添加提示', '添加成功!'); store.reload(); } else { Ext.Msg.alert('添加提示', '添加失败!'); } } else if (request.action == 'update') { if (result) { Ext.Msg.alert('提示', '更新成功!'); store.reload(); } else { Ext.Msg.alert('提示', '更新失败!'); } } else if (request.action == 'destroy') { if (result) { Ext.Msg.alert('提示', '数据删除成功'); store.reload(); } else { Ext.Msg.alert('提示', '数据删除失败'); } } } } });
这里面相应的后台程序也需要改
/// <summary> /// 更新接口信息 /// </summary> /// <param name="ic">需要更新的数据</param> public ReturnMsg Put(InterfaceConfig ic) { try { OlandHIPDBEntities db = new OlandHIPDBEntities(); var data = from item in db.InterfaceConfig where item.ID == ic.ID select item; InterfaceConfig old = data.SingleOrDefault(); old.FunctionCode = ic.FunctionCode; old.FunctionName = ic.FunctionName; old.Invoker = ic.Invoker; old.IsEnabled = ic.IsEnabled; old.Module = ic.Module; db.SaveChanges(); return new ReturnMsg() { success = true, msg = "test" }; } catch (Exception) { return new ReturnMsg() { success = false, msg = "test" }; } }
由于对Extjs的不理解,真的很费力,但如果找对了方法,看起来了又很简单,等今天把列过滤解决掉,这个项目就基本完活了。等下周就要进入wpf的开发了,唉,刚开始熟悉,又要离开,真不舍得。
再发一点牢骚,程序员的路究竟该怎么走?我其实很迷茫,样样通,公司需要。但是对自己的长期发展不利,样样通的后果就是样样不精。但是你想精通一门也不行,公司不允许,因为他是跟项目定的。有的人说要学会拒绝,但是你敢吗?汗,我也不知道自己在说什么……迷茫中
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Extjs4.2 rest 与webapi数据交互
- extjs4.0 与后台数据交互(续)
- Extjs4.2与struts后台交互弹框
- 自建 webapi rest
- WebAPI Rest机制
- REST+SPRING+webservice交互xml数据
- Androidannotation使用之@Rest与服务器交互的JSON数据转换(二)
- 钉钉开发系列(十)SaltUI与WebApi交互
- Extjs4.2与SSH框架传输json数据小例
- EXTJS4.0 3种和后台交互数据的方法
- PhoneGap 跨平台应用:HealthWorking (2) 通过REST Service与服务器交互实现登陆
- .net mvc4 Webapi Rest接口返回值
- EXTJS4自学手册——EXT数据结构组件(Model数据验证,数据交互)
- C#与Javascript数据交互
- flash与java交互数据
- C#与Javascript数据交互
- ajax与xml数据交互
- c#与matlab数据交互
- Android 屏幕自适应方向尺寸与分辨率
- 链表的一系列操作
- A Bug in Custom ISAPI Filter Related to Keep-Alive
- 一致性 hash 算法( consistent hashing )
- Hadoop分布式文件系统:架构和设计要点
- Extjs4.2 rest 与webapi数据交互
- Spring的作用域以及RequestContextListener作用
- xml的onclick
- 数学专项number_theory:UVa 294
- REST和SOAP
- 深入理解Oracle索引(24):B*Tree 索引小结
- 使用SQL Trace来实现SQL Server的跟踪操作(1)
- C语言的那些小秘密之断言
- 设置文件共享