문제

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

도움이 되었습니까?

해결책

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"}]}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top