3

I'm trying to handle event after creating new record to ExtJS store and saving it to server. But I have a problem - write event firing only after update action. Documentation says:

@event write Fires if the server returns 200 after an Ext.data.Api.actions CRUD action. Success of the action is determined in the result['successProperty']property (NOTE for RESTful stores, a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).

Now I've such response from server: [{"tid": 5, "action": "CityGrid", "type": "rpc", "method": "create", "result": {"msg": "saved", "data": {}, }}]

I guess that adding a database.pk of created object to server response should resolve problem but I've no idea how to do it. I've tried this ... "data": {"Id":my_object.id} but with no effect.

Shamanu4
  • 5,296
  • 2
  • 27
  • 31

2 Answers2

2

This example: http://dev.sencha.com/deploy/dev/examples/writer/writer.html Creating return this:

{
    "success":true,
    "message":"Created record",
    "data": {"first":"sdfds","last":"sdfsdf","email":"asd@sdfs.sd","id":10}
}

So just return store record for new object in Reader.root property.

Kriplins
  • 192
  • 9
  • Also the data property may be array of records asnoticed Mchl. It is usable when data is saving in a batch. – Shamanu4 Dec 20 '10 at 11:42
1

Try setting idProperty of your JsonReader to the name of your PK. Also, I think that data: should be an array "data": [{"id": ....}] but I might be wrong :P

Mchl
  • 61,444
  • 9
  • 118
  • 120
  • 1
    your advice is O.K - event is firing now. But the answer of Alerion is more usable - store will be updated with correct data when all fields are received, not only the pk. – Shamanu4 Dec 20 '10 at 11:39
  • And it doesn't need to be an array it seems ;) – Mchl Dec 20 '10 at 12:17