0

我正在尝试使用带有 ExtJS 4.1(Sencha Architect 2)的 REST 代理,使用 CakePHP 读取 JSON 文件,该文件在 JSON 返回数据中具有视图。

此数据不仅包含对象,还包含相关对象、Book、BookCopy 等。

我应该如何创建商店和模型才能在 Grid 中使用 JSON?现在它在 Book 列的网格中显示对象,这是我在商店中创建的一个字段(我使用自动列将商店的字段映射到网格)。

这是 JSON(它是嵌套数据和相关数据):

    [
    {
        "Book": {
            "ISBN": "1660151266",
            "title": "A Call to Arms ",
            "author": "Loren L. Coleman ",
            "pages": "44",
            "book_copy_count": "10",
            "book_available_count": "9",
            "id": "66"
        },
        "BookCopy": [
            {
                "condition_id": "1",
                "available": false,
                "book_id": "66",
                "id": "395",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "396",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "397",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "398",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "399",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "400",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "401",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "402",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "403",
                "title": "A Call to Arms "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "66",
                "id": "404",
                "title": "A Call to Arms "
            }
        ]
    },
{
        "Book": {
            "ISBN": "1003581858",
            "title": "Call of Duty ",
            "author": "Blain Lee Pardoe ",
            "pages": "52",
            "book_copy_count": "6",
            "book_available_count": "5",
            "id": "58"
        },
        "BookCopy": [
            {
                "condition_id": "1",
                "available": false,
                "book_id": "58",
                "id": "350",
                "title": "Call of Duty "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "58",
                "id": "351",
                "title": "Call of Duty "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "58",
                "id": "352",
                "title": "Call of Duty "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "58",
                "id": "353",
                "title": "Call of Duty "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "58",
                "id": "354",
                "title": "Call of Duty "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "58",
                "id": "355",
                "title": "Call of Duty "
            }
        ]
    },
    {
        "Book": {
            "ISBN": "1843871223",
            "title": "Close Quarters ",
            "author": "Victor Milan ",
            "pages": "32",
            "book_copy_count": "9",
            "book_available_count": "9",
            "id": "23"
        },
        "BookCopy": [
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "139",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "140",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "141",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "142",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "143",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "144",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "145",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "146",
                "title": "Close Quarters "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "23",
                "id": "147",
                "title": "Close Quarters "
            }
        ]
    },
    {
        "Book": {
            "ISBN": "1795387125",
            "title": "D.R.T ",
            "author": "James D. Long ",
            "pages": "71",
            "book_copy_count": "5",
            "book_available_count": "5",
            "id": "25"
        },
        "BookCopy": [
            {
                "condition_id": "1",
                "available": true,
                "book_id": "25",
                "id": "156",
                "title": "D.R.T "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "25",
                "id": "157",
                "title": "D.R.T "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "25",
                "id": "158",
                "title": "D.R.T "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "25",
                "id": "159",
                "title": "D.R.T "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "25",
                "id": "160",
                "title": "D.R.T "
            }
        ]
    },
    {
        "Book": {
            "ISBN": "1401073348",
            "title": "Dagger Point ",
            "author": "Thomas Gressman ",
            "pages": "46",
            "book_copy_count": "10",
            "book_available_count": "10",
            "id": "48"
        },
        "BookCopy": [
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "295",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "296",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "297",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "298",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "299",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "300",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "301",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "302",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "303",
                "title": "Dagger Point "
            },
            {
                "condition_id": "1",
                "available": true,
                "book_id": "48",
                "id": "304",
                "title": "Dagger Point "
            }
        ]
    }
]
4

1 回答 1

1

您必须采用默认的 ExtJS 代理配置和 CakePHP 的渲染。根据您的经验,您可以编写自己的 ExtJS 到 CakePHP 的转换,反之亦然(请参阅Hash 类),或者您可以使用 Bancha,它会为您完成所有这些工作。尤其见http://banchaproject.org/using-sencha-architect-2.html

只要您的 Store 与 CakePHP 一起使用,您就可以简单地将它用于 Grid、List、...

我希望这会有所帮助,请随时询问更多详细信息:)

于 2013-01-06T02:39:17.657 回答