PDA

View Full Version : the request param is null in store.save?



loveam
25 Sep 2009, 9:20 AM
hi,all:
I am a new ext developer, I want to save a record to server side, I am using RowEditor, at first client will load all records and show, then I will using RowEditor insert or update a record, this is my code:

var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: true
});
var store = new Ext.data.GroupingStore({
id: 'period',
//proxy: new Ext.data.HttpProxy({url:'/listperiod.html'}),


proxy: new Ext.data.HttpProxy({
api: {
read: '/listperiod.html',
update : '/saveperiod.html',
create : '/saveperiod.html',
destroy : '/deleteperiod.html'
}
}),
writer: writer,
autoSave: false,
reader: new Ext.data.JsonReader (
{
root:'periods',
autoLoad:true
},
[
{name: 'p1id', type: 'string'},
{name: 'p2id', type: 'string'},
{name: 'date', type: 'date', dateFormat: "Y-m-dTH:i:s"}
]

),
sortInfo: {field: 'date', direction: 'DESC'}
});
store.load();
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update',
listeners: {afteredit: {
fn:function(rowEditor, obj,data, rowIndex ){
store.save();
}
}
}


});


but I found request params map include 1 param named "periods", how to make client side post 1 period record?

thank you!

loveam
25 Sep 2009, 9:55 PM
hi, I update my code and try to using firebug:

var Period = Ext.data.Record.create([{
name: 'p1id',
type: 'string'
}, {
name: 'unid',
type: 'auto'
}, {
name: 'p2id',
type: 'string'
}, {
name: 'date',
type: 'date',
dateFormat: 'Y-m-dTH:i:s'
}]);


var writer = new Ext.data.JsonWriter({
encode: true,
root:'period',
writeAllFields: true
});

var store = new Ext.data.GroupingStore({
id: 'period',
proxy: new Ext.data.HttpProxy({
api: {
read: '/listperiod.html',
update : '/saveperiod.html',
create : '/saveperiod.html',
destroy : '/deleteperiod.html'
}
}),
writer: writer,
autoSave: true,
reader: new Ext.data.JsonReader (
{
recordType: Period,
fields: Period,
idProperty: 'unid',
root:'periods',
autoLoad:true
}
),
sortInfo: {field: 'date', direction: 'DESC'}
});
store.load();
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update',
listeners: {afteredit: {
fn:function(rowEditor, obj,data, rowIndex ){
store.save();
}
}
}
});

I found when I call store.save, the request param is
periods{"p1id":"6","unid":"ext-record-1","p2id":"1","date":"2009-09-26T00:00:00"}
periods is not correct, it should be period, does anybody can help me?

thank you!

loveam
25 Sep 2009, 10:11 PM
I found store.save will save all record, how to make it just save current record?

Condor
26 Sep 2009, 1:34 AM
It will save all records separately if you set batch:false.

But if you only want to save a single record you could use:

store.doTransaction(action, [record]);
(where action is 'create', 'update' or 'destroy')