我实现了简单的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数据。
答案 0 :(得分:1)
ExtJs 5及更高版本中的其余代理阅读器会查找rootProperty:
而不是root:
。
答案 1 :(得分:0)
HI你可以覆盖你班级的toString()方法。那么你就可以得到确切的结果。
就像你想要数据[" id":" aupres"," passwd":" aaa"," age& #34;:45,"名称":"约瑟夫"}] 或其他一些格式