1

I am trying to use the rootProperty value in a Sencha Touch 2 store to load some JSON I retrieved from the Foursquare Venues API and for the life of me I cannot get it to work.

According to the docs I should setup my rootProperty in dot notation to equal "response.venues" but it does not populate the list. I put the json in a separate file and removed the "response" and "venues" headers and it worked fine. There must be something blatantly obvious I'm missing here as I can't find a straight answer anywhere.

My model:

Ext.define('App.model.4SqVenue', {
extend: 'Ext.data.Model',

config: {
    fields: [
        {name: 'name', id: 'id'}
    ]
}
});

My store:

Ext.define('App.store.4SqVenues', {
extend: 'Ext.data.Store',
requires: [
    'App.model.4SqVenue'
],

config: {
    model: 'App.model.4SqVenue',
    storeId: '4SqVenuesStore',

    proxy: {
        type: 'jsonp',
        url: 'foursquare venue request',
        reader: {
            type: 'json',
            rootProperty: 'response.venues'
        }
    }
}
});

My view:

Ext.define('App.view.4SqVenues', {
extend: 'Ext.List',
xtype: '4SqVenuesCard',
requires: [
    'App.store.4SqVenues'
],

config: {
    fullscreen: true,
    itemTpl: '{name}',
    store: '4SqVenuesStore'
}
});

The response from the 4sq API:

{
"meta": {
    "code": 200
},
"response": {
    "venues": [
        {
            "id": "4a3ad368f964a52052a01fe3",
            "name": "Four Peaks Brewing Company",
            "contact": {
                "phone": "4803039967",
                "formattedPhone": "(480) 303-9967",
                "twitter": "4PeaksBrewery"
            },
            "location": {
                "address": "1340 E 8th St",
                "crossStreet": "at Dorsey Ln.",
                "lat": 33.4195052281187,
                "lng": -111.91593825817108,
                "distance": 1827,
                "postalCode": "85281",
                "city": "Tempe",
                "state": "AZ",
                "country": "United States"
            },
            "categories": [
                {
                    "id": "4bf58dd8d48988d1d7941735",
                    "name": "Brewery",
                    "pluralName": "Breweries",
                    "shortName": "Brewery",
                    "icon": {
                        "prefix": "https://foursquare.com/img/categories/nightlife/brewery_",
                        "sizes": [
                            32,
                            44,
                            64,
                            88,
                            256
                        ],
                        "name": ".png"
                    },
                    "primary": true
                }
            ],
            "verified": true,
            "stats": {
                "checkinsCount": 24513,
                "usersCount": 8534,
                "tipCount": 235
            },
            "url": "http://www.fourpeaks.com",
            "likes": {
                "count": 0,
                "groups": []
            },
            "menu": {
                "type": "foodAndBeverage",
                "url": "https://foursquare.com/v/four-peaks-brewing-company/4a3ad368f964a52052a01fe3/menu",
                "mobileUrl": "https://foursquare.com/v/4a3ad368f964a52052a01fe3/device_menu"
            },
            "specials": {
                "count": 0,
                "items": []
            },
            "hereNow": {
                "count": 1,
                "groups": [
                    {
                        "type": "others",
                        "name": "Other people here",
                        "count": 1,
                        "items": []
                    }
                ]
            }
        }
    ]
}
}
4

2 回答 2

2

我有一个非常相似的问题。如果我在没有定义 rootProperty 的情况下加载 json,基本上一切都很好。但是一旦我定义它,事情就会停止工作(在 Architect 中报告了错误的配置错误)。

所以 belwo 工作 opnlu 直到我将 rootProperty 定义为“记录”

{ "records" : [ { "artist" : "Champion",
        "index" : 1,
        "recordid" : "r00899659",
        "trackname" : "1 To 2"
      },
      { "artist" : "Champion",
        "index" : 2,
        "recordid" : "r00899668",
        "trackname" : "Is Anybody There?"
      }
      .......
    ],
  "rowcount" : 10,
  "timestamp" : "1/07/2012 5:05:19 AM"
} 
于 2012-07-01T05:08:17.030 回答
0

首先,您必须将其包装在函数调用中,作为响应的 Per 文档。然后您可能必须在模型中使用转换函数。比如设置root属性为response,然后使用convert从场地属性中引入所有其他数据。

于 2013-10-17T03:06:26.387 回答