0

我向返回数据库查询结果的 servlet 发出 ajax 请求。我可以用 firebug 看到响应,我想将这些结果放在我已经创建的列表(或其他..)中。

我试图阅读这篇文章,但它没有帮助我..

代码:

这是ajax请求:

                        Ext.Ajax.request({
                        url: '/VIProject/Container',

                        success: function (action){alert('Lista caricata!'); console.debug(action); },
                        failure: function (){alert('Errore nel caricamento...');},
                        headers: {
                            'my-header': 'foo'
                        },
                        params: { action: "GETCONTAINERLIST" }
                    });

来自 servlet(萤火虫)的响应:

{"message":"OK","container":[{"idOrdine":"1","numLotto":"123"},{"idOrdine":"2","numLotto":"321"},{"idOrdine":"3","numLotto":"876"}],"success":true}

列表:

    var listView = Ext.create('Ext.grid.Panel', {
    width:425,
    height:250,
    id: 'lista',
    collapsible:true,
    title:'Simple ListView <i>(0 items selected)</i>',
    store: //???
    multiSelect: true,
    viewConfig: {
        emptyText: 'No images to display'
    },

    columns: [{
        text: 'idOrdine',
        flex: 15,
        sortable: true,
        dataIndex: 'idOrdine'
    },{
        text: 'Last Modified',
        flex: 20,
        sortable: true,
        dataIndex: 'numLotto'
    }]
});

我能怎么做?

4

2 回答 2

0

我已修改您的代码以使用商店:

Ext.define('MyModel', {
    extend: 'Ext.data.Model',
    fields: ['idOrdine', 'numLotto']
})

var listView = Ext.create('Ext.grid.Panel', {
    width:425,
    height:250,
    id: 'lista',
    collapsible:true,
    title:'Simple ListView <i>(0 items selected)</i>',
    store: store: {
        model: MyModel,
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: '/VIProject/Container',
            reader: {
                type: 'json',
                root: 'container'
            }
        }
    },
    multiSelect: true,
    viewConfig: {
        emptyText: 'No images to display'
    },

    columns: [{
        text: 'idOrdine',
        flex: 15,
        sortable: true,
        dataIndex: 'idOrdine'
    },{
        text: 'Last Modified',
        flex: 20,
        sortable: true,
        dataIndex: 'numLotto'
    }]
});
于 2013-02-28T01:40:06.213 回答
0

即使以这种方式,它也可以工作:

        var proxy=new Ext.data.HttpProxy({url:'/VIProject/Container'});

    var reader=new Ext.data.JsonReader({},[
          {name: 'idOrdine', mapping: 'idOrdine'},
          {name: 'numLotto', mapping: 'numLotto'}
     ]);

     var store=new Ext.data.Store(    {
         proxy:proxy,
         reader:reader
     });

    store.load();

我尝试了各种方式..但我不知道该怎么做!

于 2013-02-28T18:57:23.963 回答