我正在尝试实现ExtJS和Java之间的元素通信,我正在从ExtJS向使用netty的Java服务器发送请求。如果有人能给我发送一个如何从Java端格式化响应以及如何从ExtJS端读取响应数据的示例,我将非常感谢。这是我在ExtJS方面的源代码
var store = new Ext.data.JsonStore({
autoload: true,
baseParams: {
conid : '6b09477f-aa04-4f5a-b969-05277d01f07e'
},
root: 'OpenCashTime',
proxy: new Ext.data.ScriptTagProxy({
url: 'http://localhost:8080/getOpenCash?'
}),
fields: [{name: 'Time', mapping: 'Time', type: 'int'}]
});
store.load();
store.on('load', function() {
alert(store.getTotalCount());
});
store.on('write', function() {
alert(store.getTotalCount());
});
store.on('loadexception', function() {
alert("AAAAAA");
});
store.on('metachange', function() {
//alert(store.getTotalCount());
});
store.on('update', function() {
//alert(store.getTotalCount());
});
store.on('save', function() {
//alert(store.getTotalCount());
});
store.on('datachanged', function() {
//alert(store.getTotalCount());
});当执行此代码并接收到此响应{"OpenCashTime":{"Time":1291623637000},{"Time":1294914317000}}时,即使firebug也看到它的Json,我仍然得到一个loadexception
发布于 2011-02-03 00:06:04
从标题中假设您想要将数据加载到JsonStore中,它期望一个有效的Json字符串,以及一个存储JSON对象数组的属性,该字符串将作为记录加载。属性名称在配置JsonStore时由root属性设置。
如下所示:
{
xtype: 'jsonstore',
root: 'data',
idProperty: 'ID',
fields: [
{name: 'ID', mapping: 'ID', type: 'int'}
{name: 'someDate', mapping: 'someDate', type: 'date', dateFormat: 'Y-m-d'}
],
url: 'hereBeYourURl'
}会很高兴地吃到这样的东西:
{"data":[{"ID":"1","someDate":"2002-10-02"},{"ID":"2","someDate":"2002-05-22"}]}发布于 2011-02-03 00:57:35
fields: [{name: 'Time', mapping: 'Time', type: 'int'}]
fields: [{name: 'Time', type: 'int'}] 顺便说一句,在身份映射的情况下,您可以省略它。这两个案例会给出相同的结果。
https://stackoverflow.com/questions/4875943
复制相似问题