【问题标题】:Sencha Touch JSONPReaderSencha Touch JSONPReader
【发布时间】:2012-03-07 06:57:20
【问题描述】:

使用 sencha touch 2,我尝试使用 json 代理呈现嵌套列表。 json看起来像

[
  {
    "start": "0"
  },
  {
    "format": "json"
  },
  .......
  {
    "GetFolderListing": [
        {
            "folder": {
                "total": 0,
                "id": "Calendar",
                "name": "Calendar",
                "unread": 0,
            }
        },
        {
            "folder": {
                "total": 0,
                "id": "Contacts",
                "name": "Contacts",
                "unread": 0,
            }
        },
  .......

我想使用 GetFolderListing.folder.name 作为 displayField 我的商店看起来像

Ext.define('foo.store.FolderListing', {
extend: 'Ext.data.TreeStore',
require: ['foo.model.FolderListing'],
config: {
    model: 'foo.model.FolderListing',
    recursive: true,
    proxy: {
    type: 'jsonp',
    url: 'http://localhost/?xx=yy&format=json',
    callbackKey: "jsoncallback",
    reader: {
        type: 'json',
        rootProperty: 'GetFolderListing',
        record: 'folder'
    }
}
 }
});

现在我得到的只是一个错误 未捕获的类型错误:无法读取未定义的属性“id”

谁能提供有关如何解决此问题或更好地调试它或如何进行自定义解析并将商品传回商店的见解?

谢谢

======== 更新 - 为了让 rootProperty 在阅读器中工作,json 必须是 jsonobject 而不是 json 数组,例如

{
"GetFolderListing": [
    {
        "folder": {
            "total": 0,
            "id": "Contacts",
            "name": "Contacts",
            "unread": 0,
            "leaf": "true"
        }
    },
    {
        "folder": {
            "total": 0,
            "id": "Conversation Action Settings",
            "name": "Conversation Action Settings",
            "unread": 0,
            "leaf": "true"
        }
    },
    .......

【问题讨论】:

    标签: sencha-touch sencha-touch-2


    【解决方案1】:

    您的 JSON 看起来像一个数组。错误消息意味着代码试图访问未定义变量或属性的属性。

    我的第一个猜测是阅读器没有正确配置为该数组类型 JSON 格式。

    【讨论】:

    • 是的,你是对的,为了使 rootProperty 工作,JSON 需要为第一组同级进行映射寻址。谢谢!
    猜你喜欢
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多