首页 > 代码库 > easy-ui curd方法

easy-ui curd方法

/**                       _ooOoo_                      o8888888o                      88" . "88                      (| -_- |)                      O\  =  /O                   ____/`---‘\____                 .‘  \\|     |//  `.                /  \\|||  :  |||//                 /  _||||| -:- |||||-                 |   | \\\  -  /// |   |               | \_|  ‘‘\---/‘‘  |   |               \  .-\__  `-`  ___/-. /             ___`. .‘  /--.--\  `. . __          ."" ‘<  `.___\_<|>_/___.‘  >‘"".         | | :  `- \`.;`\ _ /`;.`/ - ` : | |         \  \ `-.   \_ __\ /__ _/   .-` /  /    ======`-.____`-.___\_____/___.-`____.-‘======                       `=---=‘    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^             佛祖保佑       永无BUG *@author xiaojiang 20140826 *@desc: easyUI treegrid 公共CURL  支持单页面多个实例 *@example: *    var menuSev = new curdClass();    menuSev.setConf({        g:$("#_menug"),    //列表id        f:$("#_menuf"),    //对应表单id        k:‘mid‘,           //表单主键名称        api:{              //列表对应的CURD连接            insert:‘/Admin/MallMenu/save‘,            update:‘/Admin/MallMenu/save‘,            del:‘/Admin/MallMenu/delete‘        }    });    menuSev.init();  * */var tgcurdClass =  function(){    var  conf ={         g:‘‘,         d:‘‘,         f:‘‘,         t:‘tg‘,         k:‘‘,         api:{             insert:‘‘,             del:‘‘,             update:‘‘,         }    };    return {        "set": function( k, v ){            conf[k] = v;        },        ‘get‘: function( k ){            return conf[k];        },        ‘setConf‘:function(obj){            for( var i in obj )                this.set(i, obj[i]);        },        ‘init‘:function(){            var me = this;            me.get(‘g‘).treegrid({                onClickRow:function( v){                    me.get(‘f‘).form( ‘load‘, v );                }            });        },        ‘add‘:function(){            this.get(‘f‘).form("reset");            //设置pk为空            $( "input[name="+this.get(‘k‘)+"]").val("");        },        ‘submit‘:function( callback ){            var $f = this.get(‘f‘);                _url = this.get(‘api‘)[‘insert‘], me = this;            if( ‘‘ !== $( "input[name="+this.get(‘k‘)+"]").val() )                _url = this.get(‘api‘)[‘update‘];            $f.form(‘submit‘,{                url: _url,                onSubmit: function(){                    return $f.form(‘validate‘);                },                success: callback || function( d ){                     var msg = ‘操作失败‘, ret = eval("("+ d +")");                     if( ret.status )                         msg =  ret.info;                     $.messager.show({                         title:‘提示‘,                         msg: msg,                         timeout:2000,                         showType:‘slide‘                     });                     me.refresh();                }            });        },        ‘reset‘:function(){            this.get(‘f‘).form("reset");            //设置pk为空            $( "input[name="+this.get(‘k‘)+"]").val("");        },        ‘remove‘:function(){            var me = this, _s = me.get(‘g‘).treegrid("getSelected"),                k = me.get(‘k‘);                        if( !_s )                return ;            $.messager.confirm(‘提示‘,‘确定要删除?‘,function(r){                var p = {} ,url = me.get(‘api‘)[‘del‘];                     p[k] = _s[k];                if (r){                    $.post( url , p, function(r){                        if (!r.status){                            $.messager.show({                                title: ‘Error‘,                                msg: r.info                            });                        }else{                            me.refresh();                            me.reset();                        }                    },‘json‘);                }            });        },        //刷新列表        ‘refresh‘:function(){            this.get(‘g‘).treegrid(‘reload‘);        }    }};

 

easy-ui curd方法