2

これは私が得ているjsonの応答です。JSONLINTで確認したところ、有効と表示されていますが、列の見出しがなくても値が表示されるだけです...列名は「States」です。

 {"myTable":["VA","CA","CO","OK","PA","TX"]}

このJsonを使用してコンボボックスにロードすることは可能でしょうか

items: [{
                    xtype: 'combo',
                    id: 'iccombo',
                    scope: this,
                    store: this.store,
                    mode: 'remote',
                    minChars: 0,
                    fieldLabel: 'Short State',
                    displayField: 'States',
                    valueField: 'States',
                    typeAhead: true,
                    name: 'States',
                    labelWidth: 125,
                    anchor: '95%'
                },

これは私の店です

var store = Ext.create('Ext.data.Store', {
        autoLoad: true,
        id: 'OurData',
        scope: this,
        fields: [{ name: 'States' }],
        proxy: {
            type: 'ajax',
            url: 'GetState/getS',
            reader: {
                type: 'json',
                root: 'myTable'
                idProperty: 'States'
            }
        }
    });
4

1 に答える 1

4

箱から出して、Extにはほぼ一致するアレイリーダーがありますが、使用しているデータ形式には微調整が必​​要です。アレイリーダーは、データ形式を取得して必要な形式に変換するようにカスタマイズできます。この種のカスタマイズは、サーバーレベルで変更できない多くのサービスに共通しているため、ExtJSデータフレームワークのおかげでUIレベルで簡単に調整できます。

これは、使用できるカスタムリーダーと、例に基づく実装、およびデータをレコードごとに表示するクイックループです。

/**
 * A customized reader to convert a list to an array for the
 * ArrayReader to take
 */
Ext.define('Ext.ux.data.reader.JsonList', {

    extend: 'Ext.data.reader.Array',

    alias : 'reader.jsonlist',

    root: 'myTable',

    /**
     * this is really the guts of the change
     * convert an array of strings to an array of arrays of strings 
     */
    extractData: function (root) {
        var data;

        if (Ext.isArray(root) && !Ext.isArray(root[0])) {
            root.forEach(function (val, idx, all) {
                /* turn the value into an array */
                all[idx] = [val];
            })
        }

        data = root;

        /* hand the array of arrays up to the ArrayReader */
        return this.callParent([data]);
    }
});

store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    id: 'OurData',
    scope: this,
    fields: [{ name: 'State' }],
    proxy: {
        /* change this back to ajax to get server data */
        type: 'memory',
        url: 'GetState/getS',
        reader: {
            type: 'jsonlist'
        }
    }, 

    /* temp data for simplified demo code */
    data: {"myTable":["VA","CA","CO","OK","PA","TX"]}
});

/* just to demo that there are six records with State as the field name: */
store.each(function (rec, id, total) {
    console.log(rec.get('State'))
});
于 2012-11-13T23:48:44.050 に答える