Chinaunix首页 | 论坛 | 博客
  • 博客访问: 351894
  • 博文数量: 26
  • 博客积分: 495
  • 博客等级: 下士
  • 技术积分: 562
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-26 13:50
文章分类

全部博文(26)

文章存档

2015年(9)

2014年(6)

2013年(7)

2012年(2)

2011年(2)

分类: JavaScript

2013-05-10 14:21:22

Ext.ux.grid.RowEditor 是个非常不错的插件,但是不便之处就是不同gird 总要根据这个grid制定相应的编辑器,因为每个grid修改后post给后台的参数不一样,主要麻烦在自定义post参数上面,其实很早之前就想自己稍微扩展下,让它自动帮我识别参数,下面是代码,希望借此抛砖引玉(插入js不行,):


点击(此处)折叠或打开

  1. Ext.ns("Test", "Test.Office");
  2. Test.Office.editor=function(config){
  3.         //this.Params = Object.keys(this.rec[0].json); //取得参数索引
  4.         //Test.Office.editor.superclass.constructor.call(this,config)
  5.         var defConf={
  6.             saveText: 'Save',
  7.             listeners:{
  8.                 'afteredit':function(){
  9.                     var s =Ext.getCmp(config.gridId).getSelectionModel().getSelections();
  10.                     var Params = Object.keys(s[0].json);
  11.                     var tempArr = {};
  12.                     for(var i in Params){
  13.                         if(Params.hasOwnProperty(i)){
  14.                             tempArr[Params[i]]=s[0].get(Params[i]);
  15.                         }
  16.                     }
  17.                     //params = JSON.stringify(tempArr);
  18.                     var params = Ext.encode(tempArr);
  19.                     console.log(params);
  20.                     Ext.Ajax.request({
  21.                         url:config.url,
  22.                         method:'POST',
  23.                         //params:params,
  24.                         params:tempArr,
  25.                         success:function(response){
  26.                             var obj = Ext.decode(response.responseText);
  27.                             if(obj.success){
  28.                                                                 Ext.MessageBox.alert("提示","修改成功");
  29.                                                                 config.ds.reload();
  30.                             }else{
  31.                                                                 Ext.MessageBox.alert("提示","修改失败");
  32.                                 }
  33.                             }
  34.                         
  35.                     })
  36.                     
  37.                 },
  38.                 'canceledit':function(){
  39.                     config.ds.reload();
  40.                 }
  41.             }
  42.         };
  43.         Ext.apply(config,defConf);
  44.         Test.Office.editor.superclass.constructor.call(this,config)
  45.         
  46.         
  47.     };
  48.     
  49. Ext.extend(Test.Office.editor,Ext.ux.grid.RowEditor,{});



使用方法:

点击(此处)折叠或打开

  1. title:'ip地址',
  2.                                         items:[{
  3.                                                 xtype:'grid',
  4.                                                 id:'ipGrid',
  5.                                                 height:400,
  6.                                                 plugins:[new Test.Office.editor({"url":"/assetmgent/index.php?mod=ip&action=busindex&resourceId/","gridId":"ipGrid"})],
  7.                                                 style:{
  8.                                                         marginTop: '10px',
  9.                                                         marginRight:'5px',
  10.                                                         marginLeft:'5px',
  11.                                                 },
  12.                                                 viewConfig:{forceFit:true},
  13.                                                 selModel:new Ext.grid.RowSelectionModel({singleSelect:false}),
  14.                                                 store:new Ext.data.JsonStore({
  15.                                                         root:"data",
  16.                                                         url:"/assetmgent/index.php?mod=ip&action=busindex&resourceId="+obj.id,
  17.                                                         fields:['f_mapId','f_idc_name','f_ip','f_isp','f_status','f_remark'],
  18.                                                         autoLoad:true
  19.                                                 }),



仅供参考!
阅读(4902) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~