Sencha-touch ассоциирует модель так же, как JSON вложен.

мой вывод json:

{"Result":
{"Data":
[{"gmt_id":"1","gmt":"-12:00","secondsDiff":"-43200","Location":"Baker IslanIsland"},
{"gmt_id":"2","gmt":"-11:00","secondsDiff":"-39600","Location":"American Samoa, Samoa"},
{"gmt_id":"3","gmt":"-10:00","secondsDiff":"-36000","Location":"Hawaii, Papeete"}]}}

--Я хочу, чтобы моя модель была вложена в результат и данные, чтобы при настройке autoLoad:true в хранилище должен был быть получен доступ к ключу:значение в потоке. Но мой console.log дает []. я ошибся где-то в моей модели, пожалуйста, помогите!!!

--это моя модель

Ext.regModel('Gmt',
        {'Result':
            {'Data':
            [
                {name:'gmt_id',type:'string'},
                {name:'Location',type:'string'}
            ]
            }

        });

this is my Store to load data:

   var jsonStore = new Ext.data.Store({
                model: "Gmt",
                proxy: {
                    type: 'ajax',
                    url: 'gmt.php',
                      //url: 'data.json',
                      method: 'GET',
                      //  callback: console.log(response),
                    reader: {
                       type: 'json',
                        //root: 'Data'
                       root:'Result'
                      // type:'json' 
                },
         afterRequest: function (request, success) {
                    if (success) {
                        console.log("success");
                    } else {
                        console.log("failed");
                    }

    }             
        },
       autoLoad: true

    });

--доступ к параметрам key:value здесь

jsonStore.on('load', function(){
        var lstArr = new Array();
        var lstAr = new Array();

        jsonStore.each(function(i) {
            //var gmtdata = i.data.gmt_id;
        // console.log(i);
                lstArr.push(i.data.gmt_id);
                    lstAr.push(i.data.Location);
    });
    console.log(lstArr);
        console.log(lstAr);
    });

person nuthan    schedule 26.09.2011    source источник


Ответы (1)


Сам решил.

--Изменить корень магазина

--Установите 'Result.Data' как root

var jsonStore = new Ext.data.Store({
            model: "Gmt",
            proxy: {
                type: 'ajax',
                url: 'gmt.php',
                  //url: 'data.json',
                  method: 'GET',
                  //  callback: console.log(response),
                reader: {
                   type: 'json',

                   root:'Result.Data'

            },
     afterRequest: function (request, success) {
                if (success) {
                    console.log("success");
                } else {
                    console.log("failed");
                }


}             
    },
   autoLoad: true

});
person nuthan    schedule 29.09.2011