Domanda

Sto cercando di imitare la comunicazione tra EXTJS e Java, sto inviando richieste da EXTJS a un server Java che utilizza Netty. Vorrei apprezzare se qualcuno potesse inviarmi un esempio di come la risposta dovrebbe essere formata dal lato Java e come leggere i dati di risposta dal lato EXTJS grazie in anticipo. Questa è la mia fonte dal lato 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());
});

Quando si esegue questo codice e reciti questa risposta {"OpenCashtime": [{"time": 1291623637000}, {"time": 1294914317000}]} Ho ancora un loadexception sebbene anche Firebug vede il suo json Json

È stato utile?

Soluzione

Supponendo dal tuo titolo, che si desidera caricare i dati in JSONSTORE, si aspetta una stringa JSON valida, con una proprietà che memorizza una serie di oggetti JSON, che verrà caricata come record. Il nome della proprietà è impostato da root Proprietà quando si configura JSONSTORE.

Negozio come questo:

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

Mangerà volentieri qualcosa di simile:

{"data":[{"ID":"1","someDate":"2002-10-02"},{"ID":"2","someDate":"2002-05-22"}]}

Altri suggerimenti

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

BTW nel caso di una mappatura dell'identità puoi lasciarlo fuori. Questi due casi ti daranno gli stessi risultati.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top