1

我有一个弹簧控制器;

@RequestMapping("/showreport")
@ResponseBody
public Map<String, ? extends Object> showreport
        (parameters) 
{
    List<Object> listOne = ...;
    Object objectOne = ...;


    Map<String,Object> modelMap = new HashMap<String,Object>(3);
    modelMap.put("total", listOne.size());
    modelMap.put("data", listOne);
    modelMap.put("summary", objectOne);
    modelMap.put("success", true);
    return modelMap;
}

我有这样的 ExtJS 代码在模式窗口中显示网格

Ext.Ajax.request({                 
        url: 'url',
        params:
        {
            // parameters 
        },
        success: function (response) 
        {                     
             var jsonData = Ext.util.JSON.decode(response.responseText);

             store.proxy = new Ext.ux.data.BufferedPagingMemoryProxy(jsonData.data);
             /* what will I do */

             new Ext.Window({
                title: 'title',
                plain: true,
                border: false,
                modal: true,
                items: [grid],
                height:Ext.getBody().getViewSize().height - 100,
                width:Ext.getBody().getViewSize().width*0.8 //80%
            }).show();

        },
        failure: function (){},
     });

而我的grid、store和readers都是这样的;

    var Report = Ext.data.Record.create([
    {name: 'a'},
    {name: 'b', type: 'string'}, 
    {name: 'c', type: 'string'}, 
    {name: 'd', type: 'string'}, 
    {name: 'e', type: 'string'}, 
    {name: 'f', type: 'string'}, 
    {name: 'g'}, 
    {name: 'h'}, 
    {name: 'i', type: 'string'}, 
    {name: 'j'}, 
    {name: 'k', type: 'string'}, 
    {name: 'l', type: 'string'}
]); 


var reader = new Ext.data.JsonReader({
    totalProperty: 'total',
    successProperty: 'success',
    idProperty: 'id',
    root: 'data'
},
Report);

store = new Ext.data.JsonStore({
    id: 'reportID',
    reader: reader
});

var grid = new Ext.grid.GridPanel({
    id: 'tripDailyReportList',
    store: store,
    autoHeight : true,
    loadMask: true,
    autoHeight: true,
    columns:[
            new Ext.grid.RowNumberer(),
            {header: 'headerA', dataIndex: 'a'},
            {header: 'headerB', dataIndex: 'b'},
            {header: 'headerC', dataIndex: 'c', sortable: true},
            {header: 'headerD', dataIndex: 'd', sortable: true},
            {header: 'headerE', dataIndex: 'e', sortable: true},
            {header: 'headerF', dataIndex: 'f'},
            {header: 'headerG', dataIndex: 'g'},
            {header: 'headerH', dataIndex: 'h'},
            {header: 'headerI', dataIndex: 'i'},
            {header: 'headerJ', dataIndex: 'j'},
            {header: 'headerK', dataIndex: 'k'}
            ]
});

我想在 ajax 请求后在窗口中加载一个网格。我打开了窗口,但我无法加载存储数据。我的json是这样的;

{“总计”:56,“数据”:[{“a”:“1”,“b”:“2”,“c”:“3”,“d”:“4”,“e”:“ 5", "f": "6", "g": "7", .....}],"summary":{"a":"1","b":"2","c ":"3","d":"4","e":"5","f":"6"},"成功":true}

你能帮我解决这个问题吗?

4

2 回答 2

1

我们必须在控制器中包含 json 元标记。阅读器idProperty必须与 json 相同idProperty。比我们可以使用var jsonData = Ext.util.JSON.decode(response.responseText); grid.store.loadData(jsonData);

于 2012-11-27T14:28:40.907 回答
0

我不知道这个插件做什么,但似乎数据没有加载到存储中。也许打电话store.load()就足够了。

于 2012-02-14T07:56:34.523 回答