简体   繁体   中英

Ext Js: How to load a store from List<String>

This is my JSON data returned from the server. I am not seeing my combo getting loaded. What is wrong here?

{"suffixList":["-1","-2","-3"]}

Model:

Ext.define('ExtMVC.model.Suffix', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'suffix'}
    ]
});

Store:

 Ext.define('ExtMVC.store.Suffixes', {
        extend: 'Ext.data.Store',
        model: 'ExtMVC.model.Suffix',
        autoLoad : false,
        proxy: {
            type: 'ajax',
            url: 'http://'+window.location.host+'/populateCombo',
            reader: {
                type: 'json',
                root: 'suffixList'
            }
        }
    });

View:

{
                xtype:'combo',
                id: 'suffix',
                name: 'suffix',
                store   : 'Suffixes',
                displayField: 'suffix',
                valueField: 'suffix'
            }

You can use an ArrayStore

new Ext.data.ArrayStore({
    fields: ['suffix'],
    data: {suffixList: ['-1', '-2', '-3']},
    proxy: {
        type:'memory', //'ajax'
        reader: {
            type: 'array',
            root: 'suffixList'
        }
    }
})

The data is not formatted correctly. Each record should be an object, with properties for the store's fields. In your case, the data should look like this:

{"suffixList":[{"suffix": "-1"},{"suffix": "-2"},{"suffix": "-3"}]}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM