Какого вида должна быть json-строка?
Приветствую вас добрые программисты :)
Подскажите пожалуйста, какого вида должна быть json-строка, что бы удовлетворить требования такой вот store: var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url : 'index.php', method : 'POST' }), baseParams :{ ajax : 'yes', action : 'grid' }, reader: new Ext.data.JsonReader({ root : 'results', totalProperty : 'total', successProperty : 'success', }), fields :[ { name : 'id', type : 'int', mapping : 'id' }, { name : 'name', type : 'string', mapping : 'name' } ] }); ЗЫ. На самом деле я перебрал уже довольно много вариантов, и потратил очень много времени. Может быть в самой сторе что-то не так... Надеюсь на вашу помощь. |
{success: true, total: 500, results: [{id: 1, name: "foo"}, {id: 2, name: "bar"}]} |
Спасибо.
Но работает частично. Проблема в ридере. Если ридер убрать, а его содержимое оставить, то все работает. |
Выкинь вообще этот ридер :) и его друга прокси!
сделай так: var storage = new Ext.data.JsonStore({ url : 'index.php', method : 'POST', root : 'results', totalProperty : 'totalCount', successProperty : 'success', baseParams : { ajax : 'yes', action : 'grid' }, fields: [ { name : 'id', type : 'int', mapping : 'id' }, { name : 'name', type : 'string', mapping : 'name' } ] }); |
cmygeHm, я немного поэкспериментировал и пришел к такому решению, правда это уже после того как я наладил работу с БД через PDO(так что извиняюсь за размеры :) ). Главное что теперь все работает, и можно двигаться дальше.
var storeUsers = new Ext.data.JsonStore({ proxy : new Ext.data.HttpProxy({ url : 'index.php', method : 'POST', }), root : 'results', totalProperty : 'total', successProperty : 'success' , baseParams:{ ajax : 'yes', action : 'grid' }, fields: [ { name : 'id', type : 'int', mapping : 'ID' },{ name : 'name', type : 'string', mapping : 'NAME' },{ name : 'type', type : 'string', mapping : 'TYPE', },{ name : 'email', type : 'string', mapping : 'EMAIL', },{ name : 'code', type : 'string', mapping : 'CODE', },{ name : 'pass', type : 'string', mapping : 'PASS', },{ name : 'date_reg', type : 'string', mapping : 'DATE_REG', },{ name : 'date_last', type : 'string', mapping : 'DATE_LAST', } ] }); storeUsers.load(); |
Просто в этом куске кода:
proxy : new Ext.data.HttpProxy({ url : 'index.php', method : 'POST', }), убери строки proxy : new Ext.data.HttpProxy({и последнюю. и будешь более модным ;) Работать тоже будет. |
cmygeHm,
Ды и сейчас уже все работает... :) |
Цитата:
var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url : 'index.php', method : 'POST' }), baseParams :{ ajax : 'yes', action : 'grid' }, reader: new Ext.data.JsonReader({ root : 'results', totalProperty : 'total', successProperty : 'success', fields :[{ name : 'id', type : 'int', mapping : 'id' }, { name : 'name', type : 'string', mapping : 'name' }] }) }); В таких случаях не ленитесь перехватывать сообщения об ошибках (например в Ext.data.HttpProxy exception - там много чего узнать можно) |
Часовой пояс GMT +3, время: 23:08. |