javascript - ExtJS RESTful服务无法处理json数据

标签 javascript json rest extjs5

我实现了简单的 RESTful 服务。这些是 Rest 请求 url 和响应 json 数据。

http://localhost:8080/RESTfulTestWeb/rest/services/getJson/aupres

{"id":"aupres","passwd":"aaa","age":45,"name":"joseph"}

问题是ExtJS Store对象客户端无法处理上述json数据。这些是 ExtJS 客户端代码

Ext.define('extjs.model.Member', {
    extend: 'Ext.data.Model',

    fields : [{
        name : 'id',
        type : 'string'
    }, {
        name : 'passwd',
        type : 'string'
    }, {
        name : 'age',
        type : 'int'
    }, {
        name : 'name',
        type : 'string'
    }]  
});

Ext.onReady(function () {

    var members = Ext.create('Ext.data.Store', {

        model : 'extjs.model.Member',
        //autoLoad : true,
        proxy: {
            type: 'rest',
            url : 'http://localhost:8080/RESTfulTestWeb/rest/services/getJson/aupres',
            reader: {
                type: 'json',
                root: 'id',
            },
            writer: {
                type: 'json'
            },
            listeners: {
                exception: function(proxy, response, operation){
                    Ext.MessageBox.show({
                        title: 'REMOTE EXCEPTION',
                        msg: operation.getError(),
                        icon: Ext.MessageBox.ERROR,
                        buttons: Ext.Msg.OK
                    })
                }
            }

        },
        listeners: {
            load: function(members, operation, success) {
                if(success) {
                    alert('response : ' + members.model.length)
                } else {
                    alert('it failed')
                }
            }
        }
    })

    var onButtonClick = function() {
        members.load()
    }

响应如下所示

"response : 0"

我的 ExtJS 代码似乎无法包含 json 数据。

最佳答案

ExtJs 5 及更高版本中的其余代理读取器查找 rootProperty: 而不是 root:

关于javascript - ExtJS RESTful服务无法处理json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063177/

相关文章:

javascript - 抓取另一个对象中的特定对象

python - 从维基数据 API 获取 python 中的项目标签

java - 无法解析其中包含 List 元素的 json

javascript - 如何有效地计算给定原始日期的连续日期

javascript - 使用 Firebase 函数将数据索引到 ElasticSearch,并非所有字段都被索引

json - groovy.json.JsonSlurper 在 groovy 1.7.8 中在哪里

rest - Loopback - 如何使用 bulkUpdate 方法

java - 如何在初始化后执行 Unirest 请求

javascript - 如何仅使用 Javascript 在 div 中显示整个选择元素

javascript - 匹配空格分隔的固定字符组