在Sencha Touch 2中正确使用rootProperty

时间:2012-06-19 22:59:16

标签: sencha-touch extjs sencha-touch-2 foursquare

我试图在Sencha Touch 2商店中使用rootProperty值来加载我从Foursquare Venues API检索到的一些JSON,并且在我的生活中我无法让它工作。

根据文档我应该用点符号设置我的rootProperty等于“response.venues”但它没有填充列表。我把json放在一个单独的文件中并删除了“响应”和“场地”标题,它运行正常。我必须在这里找到一些显而易见的东西,因为我无法在任何地方找到答案。

我的模特:

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

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

我的商店:

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'
        }
    }
}
});

我的观点:

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

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

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": []
                    }
                ]
            }
        }
    ]
}
}

2 个答案:

答案 0 :(得分:2)

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

所以belwo工作opnlu直到我将rootProperty定义为'records'

{ "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"
} 

答案 1 :(得分:0)

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