Данные JSON в Sencha Touch - PullRequest
       1

Данные JSON в Sencha Touch

0 голосов
/ 04 октября 2011

Я сейчас играю с Sencha Touch и пытаюсь получить данные из инсталляции drupal с использованием JSON Views.Я просмотрел документацию по API Sencha, но не могу заставить его работать.

Мой ответ Json следующий:

{
  "spots" : [
    {
      "spot" : {
        "nid" : "10",
        "created" : "1288868246",
        "title" : "Almanarre",
        "type" : "spot",
        "city" : "Hyères",
        "country" : "fr",
        "latitude" : "43.083433",
        "longitude" : "6.148224"
      }
    },
    {
      "spot" : {
        "nid" : "11",
        "created" : "1288956341",
        "title" : "Lac de Neuchâtel",
        "type" : "spot",
        "city" : "Dakhla",
        "country" : "ma",
        "latitude" : "23.866295",
        "longitude" : "-15.738344"
      }
    },
    {
      "spot" : {
        "nid" : "12",
        "created" : "1288958572",
        "title" : "Zurich",
        "type" : "spot",
        "city" : "Zurich",
        "country" : "ch",
        "latitude" : "0.000000",
        "longitude" : "0.000000"
      }
    },
    {
      "spot" : {
        "nid" : "13",
        "created" : "1289302233",
        "title" : "Berne",
        "type" : "spot",
        "city" : "Berne",
        "country" : "ch",
        "latitude" : "46.947999",
        "longitude" : "7.448148"
      }
    },
    {
      "spot" : {
        "nid" : "14",
        "created" : "1290266721",
        "title" : "Dakhla",
        "type" : "spot",
        "city" : "Rio de Janeiro",
        "country" : "br",
        "latitude" : "-22.903539",
        "longitude" : "-43.209587"
      }
    },
    {
      "spot" : {
        "nid" : "15",
        "created" : "1299172773",
        "title" : "Paje",
        "type" : "spot",
        "city" : "Paje",
        "country" : "tz",
        "latitude" : "-6.265646",
        "longitude" : "39.535332"
      }
    }
  ]
}

И моя Модель / Магазин / Список:

Ext.regModel( 'Spot', {
            idProperty: 'id',
            fields : [
                { name: 'id', type: 'int'},
                { name: 'date', type: 'date', dateFormat: 'c' },
                { name: 'title', type: 'string'},
                { name: 'type', type: 'string'},
                { name: 'country', type: 'string'},
                { name : 'city', type: 'string' },
                { name : 'lat', type: 'string' },
                { name: 'long', type: 'string'}
            ]
        }); // Model


        Ext.regStore('spotStore', {
            model: 'Spot',
            proxy: {
                type: 'ajax',
                url: '/api/spots/',
                reader: {
                    type: 'json',
                    root: 'spots'
                },
                autoload: true
            }
        });
ks.views.spotsList = new Ext.List({
            id: 'spotsList',
            store: 'spotStore',
            itemTpl: '<div class="list-item-title">{title}</div>' + '<div class="list-item-narrative">{country}</div>',
            onItemDisclosure: function(record){

            },
            listeners: {
                'render': function (thisComponent) {
                    thisComponent.getStore().load();
                }
            }
        });

Вызов сделан, создается список с точным количеством из 6 пунктов.Но я не могу заставить переменные в itemTpl отображаться ...

Есть идеи?

Большое спасибо!

1 Ответ

0 голосов
/ 11 ноября 2011

Проблема с корневой переменной, которую вы упомянули при создании магазина. Я предлагаю некоторые изменения в формате Json т.е.

{
    "spots": [
        {
            "nid": "10",
            "created": "1288868246",
            "title": "Almanarre",
            "type": "spot",
            "city": "Hyères",
            "country": "fr",
            "latitude": "43.083433",
            "longitude": "6.148224"
        },
        {
            "nid": "11",
            "created": "1288956341",
            "title": "Lac de Neuchâtel",
            "type": "spot",
            "city": "Dakhla",
            "country": "ma",
            "latitude": "23.866295",
            "longitude": "-15.738344"
        },
        {
            "nid": "12",
            "created": "1288958572",
            "title": "Zurich",
            "type": "spot",
            "city": "Zurich",
            "country": "ch",
            "latitude": "0.000000",
            "longitude": "0.000000"
        },
        {
            "nid": "13",
            "created": "1289302233",
            "title": "Berne",
            "type": "spot",
            "city": "Berne",
            "country": "ch",
            "latitude": "46.947999",
            "longitude": "7.448148"
        },
        {
            "nid": "14",
            "created": "1290266721",
            "title": "Dakhla",
            "type": "spot",
            "city": "Rio de Janeiro",
            "country": "br",
            "latitude": "-22.903539",
            "longitude": "-43.209587"
        },
        {
            "nid": "15",
            "created": "1299172773",
            "title": "Paje",
            "type": "spot",
            "city": "Paje",
            "country": "tz",
            "latitude": "-6.265646",
            "longitude": "39.535332"
        }
    ]
}

Надеюсь, это поможет ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...