ユーザーが必要なだけ新しい行を追加するグリッドがあります。すべての行を追加したら、[保存] ボタンをクリックします。[保存] ボタンをクリックすると、ユーザーが入力したすべてのデータを 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) {
}
});
}
jsonData
しかし、ストアのコンテンツを JSON に変換して ajax リクエストで送信する方法がわかりません。
サーバー側で次のような 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'
},
]
}
これを達成する方法を教えてください。
よろしく、