1

我试图在 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}]} 尽管即使萤火虫看到它的 Json,但我仍然收到 loadexception

4

2 回答 2

2

假设您希望将数据加载到 JsonStore 中,它需要一个有效的 Json 字符串,该字符串具有存储 JSON 对象数组的属性,该属性将作为记录加载。root属性名是在配置 JsonStore 时由属性设置的。

像这样存储:

{
  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-02T16:06:03.950 回答
1
fields: [{name: 'Time', mapping: 'Time', type: 'int'}]  
fields: [{name: 'Time', type: 'int'}]  

顺便说一句,在身份映射的情况下,您可以将其省略。这两种情况会给你同样的结果。

于 2011-02-02T16:57:34.827 回答