我有一個網格,其中用戶和添加新行數儘可能多。添加完所有行後,點擊「保存」按鈕。在保存按鈕的點擊,我想給用戶以JSON格式輸入到服務器端代碼(即在我的情況下,一個servlet)網格內容JSON轉換
下面是模型和存儲定義的所有數據:
Ext.define('Plant', {
extend: 'Ext.data.Model',
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'common', type: 'string'},
{name: 'botanical', type: 'string'},
{name: 'light'},
{name: 'price', type: 'float'},
// dates can be automatically converted by specifying dateFormat
{name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
{name: 'indoor', type: 'bool'}
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
// destroy the store if the grid is destroyed
autoDestroy: true,
model: 'Plant'
});
保存按鈕的點擊,我能夠拿到店裏像這樣:
{
text: 'Save',
handler : function(){
//Getting the store
var records = grid.getStore();
console.log(records.getCount());
Ext.Ajax.request({
url: '/CellEditing/CellEditingGridServlet',
method: 'POST',
jsonData: {
//How to assign the store here such that
//it is send in a JSON format to the server?
},
callback: function (options, success, response) {
}
});
}
但我不知道怎麼樣去商店的內容轉換成JSON和Ajax請求的jsonData
發送。
我想在服務器端的JSON數據是這樣的:
{"plantDetails":
[
{
"common": Plant1,
"light": 'shady',
"price": 25.00,
"availDate": '05/05/2013',
"indoor": 'Yes'
},
{
"common": Plant2,
"light": 'most shady',
"price": 15.00,
"availDate": '12/09/2012',
"indoor": 'No'
},
]
}
請讓我知道如何做到這一點。
問候,
你應該使用代理這個。 http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Ajax –
確保並查找商店的同步功能,讓您的生活更加輕鬆,已經通過其ajax代理正確設置了商店。 –
評論真的幫了很多,請問我能告訴我以下幾個原因嗎? – user182944