0

I am using EXT JS 4.1.1.

I have a json response like this:

{ values: ["A","B","C"] }

I then have a model like so:

Ext4.define('model', {
    extends: 'Ext4.data.model',
    fields: [ 'name' ]
});

I am trying to create models with one value, name, that corresponds to the above json values so that I can use the name values in a ComboBox.

Ext4.define('store',{
    extend: 'Ext4.data.Store',
    model: 'model',
    requires: 'model',
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'values',
            successProperty: 'success'
        }
    }
});

The issue I'm having is that when populating my ComboBox with the name attribute, it is empty (""). The raw value is correct, it corresponds directly to the appropriate value.

How can I map this array of values correctly to a name field on my model model?

1 Answer 1

1

That is not actually a proper JSON response, paste it into http://jsonlint.com/ and you will see for yourself.

Instead your JSON should look like this:

{
    "values": [
        {
            "name": "A"
        },
        {
            "name": "B"
        },
        {
            "name": "C"
        }
    ]
}

Which you will see is valid if you paste into the jsonlint link above.

The store reader is expecting to see 'name' attributes in the data, but cannot, which is why you are seeing this behaviour.

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

1 Comment

Actually, jsonlint.com just accuses his JSON is not valid due to the absence of quotes on "values" key. { "values": ["A", "B", "C"] } is a valid JSON, for example.

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.