ExtJS RESTful service fail to handle json data

喜你入骨 提交于 2019-12-20 06:39:01

问题


I implement simple RESTful Service. These are Rest request url and the response json data.

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

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

The problem is ExtJS Store object client can not handle the above json data. These are ExtJS client codes

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()
    }

The respose is shown like below

"response : 0"

It seems my ExtJS codes fail to contain the json data.


回答1:


HI You can overwrite toString() method of your class . then you can get exact.

Like you want data on ["id":"aupres","passwd":"aaa","age":45,"name":"joseph"}] or some other format




回答2:


The rest proxy reader in ExtJs 5 and up looks for a rootProperty: instead of root:.



来源:https://stackoverflow.com/questions/34018041/extjs-restful-service-fail-to-handle-json-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!