1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    9
    Vote Rating
    1
    herzog is on a distinguished road

      0  

    Default Unanswered: Getting ID after create

    Unanswered: Getting ID after create


    I create a record, insert it to the store and make a sync. The create-url is called. I got an answer (the record with the id), but the record in the store do not have a changed id. When I change this record, the Update-url is called, but the ID is empty. Why? How to change the id of the record to the given db-id (from the response of the create-url).

    Create-Post:
    {"data":"id":null,"text":"text"}}
    Answer:
    {'success': true, 'message': 'Created record', 'data': {'id': 1, 'text': 'text'}}
    (I also tried to answer just "1".)

    Update-Post:
    {"data":{"id":null,"text":"text2"}}

    Code

    Ext.define('My.store.ds', {
    extend: 'Ext.data.Store',
    model: 'My.model.ds',
    proxy: {
    type: 'ajax',
    api: {
    read: '/ds/ReadK',
    create: '/ds/CreateK',
    update: '/ds/UpdateK' },
    reader: {
    type: 'json',
    root: 'ds',
    successProperty: 'success' } },
    remoteSort: true });

    Ext.define('My.model.ds', {
    extend : 'Ext.data.Model',
    fields : [{ name : 'id', type : 'int', useNull : true }, 'text'] });

    var record = Ext.create('My.model.ds');
    record.data.id = null;
    var s = Ext.getStore('ds');
    s.insert(0, record);

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    9
    Vote Rating
    1
    herzog is on a distinguished road

      1  

    Default


    I don't like it, but it works, when I add the write listener to to store:


    listeners: {
    write: function (store, operation, eOpts) {
    if
    (operation.action == 'create')
    operation.records[0].data.id = operation.response.responseText;
    }
    }

    Now I just response the id, when the create-url is called.