0

私はこのJSONを持っています:

{
    "aaa": {
        "list": {
            "count":"1",
            "data": [
                {"id":"1","username":"user1","email":"user1@test.com"}
            ]
        }
     }
}

そして、これは私の店です:

var store = Ext.create('Ext.data.Store', {
    fields : [ 'id', 
               'username', 
               'email'],
    autoLoad : true,
    proxy: {
        type: 'ajax',
        api: {
            read: 'server/users'
        },
        reader: {
            type: 'json',
            successProperty: 'success',
            root: 'data',
            messageProperty: 'message'
        }
    }
});

そして、これは私のグリッドです:

xtype: 'grid',
title: 'Users',
id: 'users', 
store: store,
columns: {
  items: [
    {text: 'ID', dataIndex: 'id', editor: 'textfield'},
    {text: 'Name', dataIndex: 'name', editor: 'textfield' },
    {text: 'Email', dataIndex: 'email', editor: 'textfield' },
]
},

しかし、このコードは機能していません。グリッドに JSON データを表示しません。問題は、JSON 要素に到達していないことだと思います。
この要素に到達するにはどうすればよいですか? (aaa.data.id、aaa.data.name、aaa.data.email が機能しない)

4

3 に答える 3

1

JSON の構造を変更したくない (または変更できない) ため、ストアのプロキシのリーダーを JSON のデータ構造に対応するように変更します。

reader: {
    type: 'json',
    rootProperty: 'aaa.list.data',
    totalProperty: 'aaa.list.count'
}
于 2015-09-15T20:32:48.377 に答える
0

ストア処理が行われる前に、リーダーの変換メソッドを使用してデータをフォーマットできます。

于 2015-09-15T20:44:57.507 に答える
0

であるroot必要がありますroot: 'aaa.list.data'。はroot、レコードの配列を指しているはずです。data返される最上位オブジェクトにはまったく表示されません。次のように言います。

var o = {
    aaa: {
        data: [{}]
    }
}
console.log(o.data); // Nothing
于 2015-09-15T20:31:01.610 に答える