Sencha Touch JSONPReader

发布于 2025-01-06 08:32:40 字数 1714 浏览 7 评论 0原文

使用 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 作为显示字段 我的商店看起来

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"
        }
    },
    .......

Using sencha touch 2, am trying to render a nestedlist with json proxy.
The json looks like

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

I want to use GetFolderListing.folder.name as the displayField
My store looks like

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

Right now all i get is an error
Uncaught TypeError: Cannot read property 'id' of undefined

Could anyone provide insight on how to solve this or debug it better or how to do custom parsing and pass items back to a store?

Thanks

========
Update - in order for the rootProperty to work in the reader, the json had to be a jsonobject rather than a json array e.g.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独留℉清风醉 2025-01-13 08:32:40

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

我的第一个猜测是读取器没有针对该数组类型 JSON 格式进行正确配置。

Your JSON looks like an array. The error message means that the code tries to access a property of a undefined variable or property.

My first guess would be that the reader is not properly configured for that array type JSON format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文