介绍一下批量提交grid中数据的问题
js文件中的提交方法如下:
listeners: {
click: function btnClick(button) {
var win = button.up('window');
var form = win.down("form");
var loadMarsk = new Ext.LoadMask(win, {//元素、DOM节点或id, {
msg: '正在执行,请稍候...',
removeMask: true// 完成后移除
});
loadMarsk.show();
var grid = form.down("grid");
var store = grid.getStore();
//
//var store = win.down("grid").getStore();
var m = store.getRange(0, store.getTotalCount()); //store.getModifiedRecords().slice(0);
var jsonArray = [];
Ext.each(m, function (item) {
jsonArray.push(item.data);
});
Ext.Ajax.request({
method: 'POST',
url: '/FoolProof/Savelist',
success: function (response) {
var o = Ext.decode(response.responseText.toString());
var center_store = Ext.ComponentQuery.query("Ali_FoolProofCenterList")[0].getStore();
center_store.loadPage(1);
console.log(o);
Ext.Msg.alert('提示', o.data.message);
loadMarsk.hide();
},
failure: function () {
Ext.Msg.alert("错误", "与后台联系的时候出了问题。");
loadMarsk.hide();
},
params: 'data=' + encodeURIComponent(Ext.encode(jsonArray))
});
win.close();
}
}
------------------------------------
controller中的方法如下:
public JsonResult Savelist(string data)
{
return this.ReturnAjaxResultJson(() =>
{
try
{
string list = HttpUtility.UrlDecode(data);
if (list.StartsWith("[") == false)
{
list = "[" + list;
}
if (list.EndsWith("]") == false)
{
list = list + "]";
}
List<FoolProofCenter> instanceList = JsonConvert.DeserializeObject<List<FoolProofCenter>>(list);
int result = nService.Savelist(instanceList, CurrentUser.USER_ID);
if (result > 0)
{
return SingleReturnObject.BuildSingleInfo(true, "保存成功!", null);
}
else
{
return SingleReturnObject.BuildSingleInfo(true, "保存失败!", null);
}
}
catch (Exception e)
{
return SingleReturnObject.BuildSingleInfo(false, e.Message, null);
}
});
}
--------------向grid中插入l临时数据--------------------------------
---------------查找记录是否存在,不存在插入store中-------------------
{
text: "Add",
action: "Add",
listeners: {
click: function (btn) {
var form = btn.up("form");
if (!form.isValid()) {
return;
}
var obj = form.getValues();
var fct_name = form.down("combo[name=FactoryCode]").getRawValue();
var line_name = form.down("combo[name=Line]").getRawValue();
var grid = form.down("grid");
var myStore = grid.getStore();
var pk_value = obj.FactoryCode + obj.Line + obj.GBMCode + obj.ApplyArticleCode + obj.ApplyLocation;
var existRecord = myStore.findRecord("pk", pk_value, 0, false, false, true);
//console.log(existRecord);
if (existRecord == null) {
var s = Ext.String.format(
'([{"FCT_CODE":"{0}", "LINE_CODE":"{1}", "GBM_CODE":"{2}", "FPRF_APLY_ART_CODE":"{3}", "APLY_LOC_CODE":"{4}", "RMK":"{5}","DEL_YN":"{6}", "USE_YN":"{7}", "FCT_NM":"{8}", "LINE_NM":"{9}","pk":"{10}"}])'
, obj.FactoryCode, obj.Line, obj.GBMCode, obj.ApplyArticleCode, obj.ApplyLocation, obj.Remark, "N", obj.ResultYN, fct_name, line_name,pk_value);
//console.log(s);
var record = eval(s);
myStore.insert(0, record);
myStore.sort();
grid.getView().refresh();
}
}
}
},
-------------grid中定义store---------------------------
xtype: "grid",
store: Ext.create('Ext.data.Store', {
fields: ["FCT_CODE", "LINE_CODE", "GBM_CODE", "FPRF_APLY_ART_CODE", "APLY_LOC_CODE", "RMK",
"DEL_YN", "USE_YN", "FCT_NM", "LINE_NM", "pk"],
data: {
'items': [
//{ 'FileName': '', "FilePath": "", "Result": "" }
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
}),
--------------------------------------------------------------
store: Ext.data.StoreManager.lookup('employeeStore'),
----------------------------------------------------------