2

Im using ExtJS 4.2. I have following code:

Ext.define('Model', {
    extend: 'Ext.data.Model',
    fields: [{
        name: 'id',
        type: 'int'
    }, {
        name: 'type',
        type: 'string'
    }, {
        name: 'type_id',
        type: 'int'
    }],

    proxy: {
        type: 'ajax',
        api: {
            update: 'localhost/update'
        },
        reader: {
            type: 'json',
            root: 'data' 
        },
        writer: {
            root: 'data',
            encode: true
        }
    }
});

var record = new Model({
    id: 100,
    type_id: 2
});
record.phantom = false;

record.save({
     success: function(record) {
          console.log(record.get('type')); 
     }
});

Param of request localhost/update:

data: {id: 100, type_id: 2}

Response:

data: {id: 100, type_id: 2, type: 'type of record'}

Why it

console.log(record.get('type'));

displays null?

1 Answer 1

1

You may have to add "success": true to your response or set successProperty to null on your reader.

Sign up to request clarification or add additional context in comments.

4 Comments

Why? Request is successful. record.get('type_id') returns 2.
Why you removed your answer with my clarification?
Because with your clarification I realized that you were not trying to load a record, but to save it.
I suggest to try adding success: true to your response because, as shown in the docs link, the proxy's json reader is configured to expect it by default. I've not read through the relevant code to be sure that it is enforced, but that's a possible cause. Regarding, the fact that you can read the type_id from your record, in the code you're showing you put it in there yourself when you create the model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.