Приветствую! Пытаюсь построить динамический grid на основе json данных.
| Код | function Grid(urlHead, urlData){ var grid = new Ext.grid.GridPanel({});
Ext.Ajax.request({ loadMask: true, url: urlHead, success: function(response, callOptions){ var store = new Ext.data.JsonStore({ url: urlData, });
grid = new Ext.grid.GridPanel({ store: store, columns: Ext.encode(response.responseText),
height: 300, title: 'Basic GridView', iconCls: 'icon-grid',
bbar: new Ext.PagingToolbar({ pageSize: 10, store: store, displayInfo: true, }) }); }, failure: function(response, callOptions) {} }); return grid; }
|
JSON заголовка таблицы:
| Код | [ {header: "ID", width: 4, sortable: true, dataIndex: 'id'}, {header: "Name", width: 50, sortable: true, dataIndex: 'last'} ]
|
JSON таблицы:
| Код | {"success":true,"message":"Loaded data","data":[{"id":1,"first":"Fred","last":"Flintstone","email":"[email protected]"},{"id":2,"first":"Wilma","last":"Flintstone","email":"[email protected]"},{"id":3,"first":"Pebbles","last":"Flintstone","email":"[email protected]"},{"id":4,"first":"Barney","last":"Rubble","email":"[email protected]"},{"id":5,"first":"Betty","last":"Rubble","email":"[email protected]"},{"id":6,"first":"BamBam","last":"Rubble","email":"[email protected]"}]}
|
Вся проблема в том, что columns: Ext.encode(response.responseText) не конвертирует содержимое JSON в javascript список. Или возможно проблема в том, что я пытаюсь неправильно работать с json. |