Results 1 to 4 of 4

Thread: Get record Id after insert to store

  1. #1
    Sencha User ycuk's Avatar
    Join Date
    Sep 2011
    Posts
    7

    Default Get record Id after insert to store

    I insert the record:

    PHP Code:
    var rec = new Writer.Login({login'New user'passgenerate_password(), access4});
    this.store.insert(0rec); 
    PHP Code:
        var storelogins Ext.create('Ext.data.Store', {
            
    model'Writer.Login',
            
    autoLoadtrue,
            
    autoSynctrue,
            
    proxy: {
                
    type'ajax',
                
    batchActionstrue,
                
    api: {
                    
    readindexphp '?model=logins&action=view',
                    
    createindexphp '?model=logins&action=create',
                    
    updateindexphp '?model=logins&action=update',
                    
    destroyindexphp '?model=logins&action=destroy'
                
    },
                
    reader: {
                    
    type'json',
                    
    successProperty'success',
                    
    root'data',
                    
    messageProperty'message'
                
    },
                
    writer: {
                    
    type'json',
                    
    writeAllFieldsfalse,
                    
    root'data'
                
    }
            }
        }); 
    returned text from create: indexphp + '?model=logins&action=create':
    {"success":true,"message":"Created record","data":{"id":19,"login":"New user","pass":"lof0h5qy","access":4}}
    now i want get the id property in the data.
    and show window with form for edit record.

    PHP Code:
    Ext.getCmp('formloginidcard').setActiveRecord(rec || nullthis); 
    here id property is null in rec var

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    Been a long time since I have used a Writer but are you sure your response is correct? What if you change the login on the server side, does it change the Model instance?
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    chramer's Avatar
    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    316
    Answers
    64

    Lightbulb

    This is not admisible :
    Code:
    {"success":true,"message":"Created record","data":{"id":19,"login":"New user","pass":"lof0h5qy","access":4}}
    you should have something like :
    Code:
    {"success":true},{"message":"Created record"},{"data":{"id":19,"login":"New user","pass":"lof0h5qy","access":4}}

  4. #4
    Sencha User ycuk's Avatar
    Join Date
    Sep 2011
    Posts
    7

    Default

    mitchellsimoens, chramerresponse is correct.
    After an insert, record is inserted into the grid with the id, but returned record from store.getAt(0) has id property is null.
    I think that it is necessary to use listener because the POST query (in firebug) works after a call:
    --var rec = new Writer.Login({login: 'New user', pass: generate_password(), access: 4});
    --this.store.insert(0, rec);

    --Ext.getCmp('formloginidcard').setActiveRecord(rec || null, this);
    --var r =
    store.getAt(0);
    --console.log(rec);
    --Here works query to the server
    --and
    the answer comes back

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •