我实现了简单的 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/