-
23 Jun 2011 10:27 AM #1
How must I configure an answer by update, destroy or create if I use an DirectProxy
How must I configure an answer by update, destroy or create if I use an DirectProxy
Hi!
What kind of informations must be included in the server answer?
If I add update a record with ID 6. Must be this id included in the answer? Also an success: true / false, when the operation failed?
-
24 Jun 2011 2:09 AM #2
as usual the success property, and the complete record data.
vg Steffen
--------------------------------------
Release Manager of TYPO3 4.5
energlobe.de - german online magazine
-
24 Jun 2011 5:19 AM #3
hm... if I send to the server
it should be returnCode:{ "tid":5 "action":"RPCAction", "method":"createFolderNode", "data":[{ "id":"", "text":"test", "leaf":true, "parentId":"184936bf-3395-4c6f-92d5-52d96d462831", "index":3, "depth":2, "checked":null }], "type":"rpc",[/INDENT]};
or is it wrong, because the id has changed?Code:{ "tid": 5, "action": "RPCAction", "method": "createFolderNode", "result": { "success": true, "error": "", "message": "Erfolgreich angelegt", "data": [ { "id": "neue_vergebene_ID", "text": "test", "leaf": true, "parentId": "184936bf-3395-4c6f-92d5-52d96d462831", "index": 3, "depth": 2 } ] }, "type": "rpc" }
my store fires after sync() an datachanged event, but nothing happen. The records are still phantom or dirty. there are also no changes on the record in store.
If I catch the write event an look into the operation, operation.wasSuccessful() is true.
-
13 Jul 2011 2:44 AM #4
Hi
I'm searching for the same solution. Would be great if someone can help.
-
5 Aug 2011 1:35 AM #5
You can send the record inside a root property like in the example above (data) or directly embed the record in the result property.
Here an example of such a request/response.
Request
ResponseCode:{ "action": "person4Action", "method": "create", "data": [ { "lastName": "New", "firstName": "Person", "id": "", "street": "Street", "city": "City", "state": "State", "zip": "Zip" } ], "type": "rpc", "tid": 3 }
Code:[ { "method": "create", "result": [ { "id": "5007", "state": "State", "country": null, "fullName": null, "lastName": "New", "zip": "Zip", "firstName": "Person", "street": "Street", "city": "City" } ], "action": "person4Action", "tid": 3, "type": "rpc" } ]
It's important that the result property is an array, because the class Ext.data.reader.Reader (function: readRecords) only recognizes it as the root object if it's an array.
Here the code from the readRecords function:
This also works because "success" is true by default if you don't send such a property back.Code:var root = Ext.isArray(data) ? data : me.getRoot(data),
Here an online demo where you see this in action:
http://extdirectspring.ralscha.ch/de...-rowedit4.html
If you send the record back in another property (data) like in your example, you have to specify this property as the root.
In this case you have to specify the root "data". Here an example where this is done inside a model class.Code:{ "tid": 5, "action": "RPCAction", "method": "createFolderNode", "result": { "success": true, "error": "", "message": "Erfolgreich angelegt", "data": [ { "id": "neue_vergebene_ID", "text": "test", "leaf": true, "parentId": "184936bf-3395-4c6f-92d5-52d96d462831", "index": 3, "depth": 2 } ] }, "type": "rpc"
You could also configure this in the store configuration.Code:Ext.define('Person', { extend: 'Ext.data.Model', fields: [ 'lastName', 'firstName', 'id', 'street', 'city', 'state', 'zip' ], proxy: { type: 'direct', api: { read: RPCAction.read, create: RPCAction.createFolderNode, update: RPCAction.update, destroy: RPCAction.destroy }, reader: { root: 'data' } } });
-
8 Dec 2011 3:24 AM #6
Should the store be updated by the framework on a create ?
Should the store be updated by the framework on a create ?
I have something very similar to the above and find that my store doesnt update form a model.save() when a new record is being created. [ v4.0.7 ]
The JSON returned is the same format as for an update save which refreshes the store record ok.
The model has an id as an int, which for a newly created record is sent to the server with id = 0.
Of course on the return this id is populated with the new key value.
So should the store be updated by the framework?
Or can it only do this for updates as it matches on ids only. [ my store just happens to only ever contain one record ]
Or should I include its temporary record id in the server request/response to allow it to match the record?
My success callback on save gets the original store record passed in as the first parameter [ phantom is now false ]
but it still has the id = 0 and no further updated fields from the save response JSON.


Reply With Quote