日期:2014-05-16  浏览次数:20360 次

extjs通用CRUD方法
/**
* 添加事件
* @param {} saveButton
* @param {} gridObj
* @param {} idName
* @param {} treeObj
* @param {} url
* @param {} assistFunc
* @returns {}
*/
function commGridInsertAction(saveButton,gridObj,idName,treeObj,url,assistFunc){
if(saveButton != null && saveButton != undefined){
if(assistFunc){
assistFunc();
}
saveButton.on("click",function(){
var sd = gridObj.getStore();
conn.request({
url : url,
    params : {},
success: function(response, opts){//成功操作
var obj = Ext.decode(response.responseText)[0];
var Plant = gridObj.getStore().recordType;
                var p = new Plant(obj);
                gridObj.stopEditing();
                sd.insert(0, p);
               gridObj.startEditing(0, 2);
},
failure:function() {//失败操作
Ext.Msg.alert("提示", "添加数据失败...");
                }
        })
});
}
}
/**
* 删除事件
* @param {} deleteButton
* @param {} gridObj
* @param {} idName
* @param {} treeObj
* @param {} url
* @param {} assistFunc
* @returns {}
*/
function commGridDeleteAction(deleteButton,gridObj,idName,treeObj,url,params,assistFunc){
if(deleteButton != null && deleteButton != undefined){
if(assistFunc){
assistFunc();
}
deleteButton.on("click",function(b,e){
var sd = gridObj.getStore();
var rs = gridObj.getSelectionModel().getSelections();
var length = rs.length;
if(length > 0){
var ids_data = "";
var dis_array = new Array();
for (var i = 0; i < length; i++) {
if(i==0){
ids_data = rs[i].get(idName);
}else{
ids_data =  ids_data + ","+rs[i].get(idName);
}
dis_array.push(rs[i].get(idName));
}
var para = params;
para[idName] = ids_data;
conn.request({
url: url,
    params : para,
success: function(response){//成功操作
sd.reload();
//循环删除gird的垃圾数据
for (var i = 0; i < length; i++) {
sd.remove(rs[i]);
}
Ext.example.msg("提醒","您已经成功删除数据");
},
failure:function() {//失败操作
Ext.Msg.alert("提示", "删除数据失败...");
                }
            })
}else{
Ext.Msg.alert("提示", "您还没有选择要删除的数据...");
}
})
}
}
/**
* 批量更新
* @param {} listupdate
* @param {} gridObj
* @param {} treeObj
* @param {} url
* @param {} assistFunc
* @param {} canUpdateFields
* @returns {}
*/
function commGridListUpdateAction(listupdate,gridObj,treeObj,url,assistFunc,canUpdateFields){
if(listupdate != null && listupdate != undefined){
if(assistFunc){
assistFunc();
}
listupdate.on("click",function(){
var sd = gridObj.getStore();
var objs = sd.getModifiedRecords();
var objData = new Array();
var model = null;
if(objs.length == 0){
Ext.example.msg("提醒","没有要保存的数据");
return;
}else{
for(var i = 0 ; i<objs.length