0

使用此处给出的教程,我正在制作一个应用程序来从 URL 获取 json 数据并显示它。我正在使用此代码来调用 URL 并进行解析。

{
                    xtype: 'nestedlist',
                    title: 'Blog',
                    iconCls: 'star',
                    cls: 'blog',
                    displayField: 'title',

                    store: {
                        type: 'tree',

                        fields: ['uuid', 'display'


                        ],

                        root: {
                            leaf: false
                        },

                        proxy: {
                            type: 'scripttag',
                            url: 'http://localhost:8081/openmrs-standalone/ws/rest/v1/location',
                            reader: {
                                type: 'json',
                                rootProperty: 'results'
                            }
                        },

                    },

                },

在控制台中,我得到了表单的响应

{
    "results": [
        {
            "uuid": "c0937f0c-1691-11df-97a5-7038c432aabf",
            "display": "Chulaimbo",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937f0c-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "c0937d4f-1691-11df-97a5-7038c432aabf",
            "display": "Mosoriot Hospital",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937d4f-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
            "display": "Unknown Location",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
                    "rel": "self"
                }
            ]
        }


    ]
}

但它显示错误 在此处输入图像描述 “位置”是服务的名称。

4

2 回答 2

0

控制台认为您正在尝试将 JSON 作为代码执行。所以在第一个之后{,它需要指令。不是数据。尝试在整个内容周围加上括号:

{ myfield: 1, anotherfield: 2 } (ERROR)

({ myfield: 1, anotherfield: 2 }) (SUCCESS)

这将解决问题。

于 2014-02-27T19:22:53.033 回答
0

我使用不同的方法完成了它。我使用代理类型“rest”并在同一服务器和端口上运行 OpenMRS 和我的应用程序,否则我的 OpenMRS 实例将不允许跨域调用。这个问题中的问题是使用类型作为“scripttag”,我仍然不知道它有什么问题。使用“rest”可以解决它。

于 2014-03-01T17:25:08.277 回答