ExtJS JsonStore 和 Netty

发布于 2024-10-15 16:49:53 字数 1196 浏览 4 评论 0原文

我试图在 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}]} 我仍然得到一个 loadException 尽管即使 firebug 也看到了它的 Json

Im trying to impelement comunication between ExtJS and Java I'm sending requests from ExtJS to a Java server thats using netty. I would appriciate if someone could send me an example of how the response should be formated from the java side and how to read the response data from the ExtJS side thanks in advance.
This is my source from the ExtJS side

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());
});

When executing this code and reciving this response {"OpenCashTime":[{"Time":1291623637000},{"Time":1294914317000}]} I still get a loadexception although even firebug sees its Json

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回梦 2024-10-22 16:49:53

根据您的标题,假设您想要将数据加载到 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"}]}

Assuming from your title, that you want to load data into JsonStore, it expects a valid Json string, with a property storing an array of JSON objects, that will be loaded as records. The property name is set up by root property when configuring JsonStore.

Store like this:

{
  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'
}

Will gladly eat something like this:

{"data":[{"ID":"1","someDate":"2002-10-02"},{"ID":"2","someDate":"2002-05-22"}]}
九厘米的零° 2024-10-22 16:49:53
fields: [{name: 'Time', mapping: 'Time', type: 'int'}]  
fields: [{name: 'Time', type: 'int'}]  

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

fields: [{name: 'Time', mapping: 'Time', type: 'int'}]  
fields: [{name: 'Time', type: 'int'}]  

BTW In the case of an identity mapping you can leave it out. These two cases will give you
the same results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文