如何从 extjs 4.2 中的商店获取对象数组并将其发送到服务器端? [英] how to get array of objects from store in extjs 4.2 and send it to server side?
问题描述
大家好,我正在使用 Extjs 4.2 数据网格,我需要将我的商店"转换为 json 数组并将其发送到服务器端(即 java).
Hiii all, I am using Extjs 4.2 data grid and i have a requirement to convert my 'store' into json array and send that to server side(i.e java).
这是我的模型.
Ext.define('Writer.Document',{
extend: 'Ext.data.Model',
fields: ['id', 'name', 'notes', 'Type', 'date']
});
而我的商店(其中包含对象列表)是
and my store (which contains list of objects) is
var store = Ext.create('Ext.data.Store', {
model: 'Writer.Document',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'findPatientRecordAction',
reader: {
type: 'json',
successProperty: 'success',
root: 'prognosis',
messageProperty: 'message'
}
fields: ['id','name', 'date', 'notes' , 'Type'],
},
});
因此,在一次提交网格中的值时,我需要在我的服务器端有一个 ist 对象.所以我需要从客户端发送 JSON 数组.
So while submitting the values in the grid at a time i require a ist object in my server side . So I need to send JSON Array from client side.
任何人都可以在这里帮助我如何从我的商店制作一个 JSONArray 对象并发送到服务器端???
Can anyone please help me out here how to make a JSONArray object from my store and send to Server side???
问候:开发
推荐答案
这里有一个简单的例子说明如何做你想做的事:
Here's a simple example of how to do what you want:
function sendGridData(){
var sendDataArray = [];
store.each(function(record){
var recordArray = [
record.get("id"),
record.get("name"),
record.get("date"),
record.get("notes"),
record.get("Type")
];
sendDataArray.push(recordArray);
});
Ext.Ajax.request({
url: "your_url_here.jsp",
success: function(response, opts){
//?
},
failure: function(response, opts) {
alert("server-side failure with status code " + response.status);
},
params: {
grid_data: Ext.encode(sendDataArray);
}
});
}
这篇关于如何从 extjs 4.2 中的商店获取对象数组并将其发送到服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!