ck504323276
ck504323276
2015-12-11 01:41

关于ext入门的数据显示问题

  • ext
  • metadata
  • 数据

前台代码

Ext.onReady(function(){

      var newFormWin;
        var userform;
        var data = [   
                    ['1', '2','3'],   
                    ['2', '2','3'],  
                    ['3', '2','3']


                ]; 
        // create the Data Store  数据
        var store = new Ext.data.Store({
             reader:new Ext.data.ArrayReader({
                 fields : [  
                           {name : 'member_id',type : 'string'},    
                           {name : 'member_name',type : 'string'} ,
                           {name : 'parent_id',type : 'string'}  
                          ]  
                 //new Ext.data.ArrayReader({
                // root: data,
                 //totalProperty: 1,
                // fields:["member_id","member_name","parent_id"]
             }),

            // load using script tags for cross domain, if the data in on the same domain as
            // this page, an HttpProxy would be better
            proxy:new Ext.data.MemoryProxy(data)
                //new Ext.data.HttpProxy({
                //url: 'http://localhost:8088/manager/getList.action'
            //})
        });
        store.load({params:{start:0, limit:10}});
        //分页显示用户数据
        var grid = new Ext.grid.GridPanel({

            autoHeight : true,
            width:700,//宽度
            //height:300,//高度
            title:'用户信息表',
            store: store,//数据        
            //加载的图标是否显示
            loadMask: false,
            //单行选中

            // grid columns列
            columns:[
           // new Ext.grid.CheckboxSelectionModel({singleSelect : false}),//复选框
            //new Ext.grid.RowNumberer(),//序号
            {
                // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
                header: "用户名",
                dataIndex: 'member_id',
                //align: 'center',
                sortable: false
            },{
                header: "年龄",
                dataIndex: 'member_name',
                //align: 'center',
                sortable: false
            },{
                header: "电话",
                dataIndex: 'parent_id',
                //align: 'center',
                sortable: false
            }]


        });
        // render it显示的层

        grid.render('grid');
        // trigger the data store load  加载用户

  })
  </script>




后台代码
public String getList() throws IOException{
        HttpServletResponse response=ServletActionContext.getResponse();
        try{
//      String json= "{"+
//        "metaData:{"+
//         " totalProperty:'results',"+
//          "root:'rows',"+
//          "fields:["+
//          "{name:'member_id',mapping:'member_id'},"+
//            "{name:'member_name',mapping:'member_name'},"+
//            
//            
//            "{name:'parent_id',mapping:'parent_id'}"+
//            
//            
//          "]"+
//          
//        "},"+
//        "results:"+1+","+
//        "rows:[{member_id:'1',member_name:'zhangsan',parent_id:'3'}]"+
//      
//      "}";
//      response.setCharacterEncoding("utf-8");
//      System.out.print(json.toString());
//      response.getWriter().write("{metaData:{ totalProperty:'results',root:'rows',fields:[{name:'member_id',mapping:'member_id'},{name:'member_name',mapping:'member_name'},{name:'parent_id',mapping:'parent_id'}]},results:1,rows:[{member_id:'1',member_name:'2',parent_id:'3'}]}");   
        response.getWriter().write("{totalProperty:1,data:[{member_id:'1',member_name:'2',parent_id:'3'},{member_id:'1',member_name:'2',parent_id:'3'}]}");
        }catch(Exception e){

        }
        return null;
    }

    之前在网上试了好几种例子,后台传的json字符串改了不知道多少次,前台页面一直是个loading,后来换成直接在前台把json数据写死,loading没了,也没数据。我是刚接触ext,不知道这是什么问题,不像java或者js,可以报错还能定位到问题。

    ![图片说明](https://img-ask.csdn.net/upload/201512/11/1449798974_130590.png)
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换