1. #1
    Ext JS Premium Member
    Join Date
    Sep 2009
    Posts
    83
    Vote Rating
    3
    el.weilando is on a distinguished road

      0  

    Default 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?

  2. #2
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    as usual the success property, and the complete record data.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  3. #3
    Ext JS Premium Member
    Join Date
    Sep 2009
    Posts
    83
    Vote Rating
    3
    el.weilando is on a distinguished road

      0  

    Default


    hm... if I send to the server

    Code:
    {
    "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]};
    it should be return

    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"
    }
    or is it wrong, because the id has changed?

    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.

  4. #4
    Sencha User
    Join Date
    Jun 2011
    Location
    Prague
    Posts
    38
    Vote Rating
    0
    cubernatic is on a distinguished road

      0  

    Default


    Hi
    I'm searching for the same solution. Would be great if someone can help.

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2010
    Posts
    116
    Vote Rating
    10
    ralscha will become famous soon enough

      0  

    Default


    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
    Code:
    {
        "action": "person4Action",
        "method": "create",
        "data": [
            {
                "lastName": "New",
                "firstName": "Person",
                "id": "",
                "street": "Street",
                "city": "City",
                "state": "State",
                "zip": "Zip"
            }
        ],
        "type": "rpc",
        "tid": 3
    }
    Response
    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:
    Code:
    var root    = Ext.isArray(data) ? data : me.getRoot(data),
    This also works because "success" is true by default if you don't send such a property back.

    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.

    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"
    In this case you have to specify the root "data". Here an example where this is done inside a model class.

    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'
            }
        }
    });
    You could also configure this in the store configuration.

  6. #6
    Sencha User
    Join Date
    Dec 2011
    Posts
    1
    Vote Rating
    0
    Jim_B is on a distinguished road

      0  

    Question 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.