【发布时间】:2016-03-05 05:40:17
【问题描述】:
我实现了简单的 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 数据。
【问题讨论】:
-
您是否在没有
reader和writer配置的情况下进行了测试? (建议:一定要在模型中配置代理,因为代理和模型是绑定的)
标签: javascript json rest extjs5