数据如下:{"root":[{"age":20,"birthday":"2012-02-22","demo":"备注信息哈0","name":"张0","sex":"男"},{"age":21,"birthday":"2012-02-22","demo":"备注信息哈1","name":"张1","sex":"男"},{"age":22,"birthday":"2012-02-22","demo":"备注信息哈2","name":"张2","sex":"男"},{"age":23,"birthday":"2012-02-22","demo":"备注信息哈3","name":"张3","sex":"女"},{"age":24,"birthday":"2012-02-22","demo":"备注信息哈4","name":"张4","sex":"女"},{"age":25,"birthday":"2012-02-22","demo":"备注信息哈5","name":"张5","sex":"女"},{"age":26,"birthday":"2012-02-22","demo":"备注信息哈6","name":"张6","sex":"女"},{"age":27,"birthday":"2012-02-22","demo":"备注信息哈7","name":"张7","sex":"女"},{"age":28,"birthday":"2012-02-22","demo":"备注信息哈8","name":"张8","sex":"男"},{"age":29,"birthday":"2012-02-22","demo":"备注信息哈9","name":"张9","sex":"男"},{"age":30,"birthday":"2012-02-22","demo":"备注信息哈10","name":"张10","sex":"女"},{"age":31,"birthday":"2012-02-22","demo":"备注信息哈11","name":"张11","sex":"男"},{"age":32,"birthday":"2012-02-22","demo":"备注信息哈12","name":"张12","sex":"男"},{"age":33,"birthday":"2012-02-22","demo":"备注信息哈13","name":"张13","sex":"男"},{"age":34,"birthday":"2012-02-22","demo":"备注信息哈14","name":"张14","sex":"女"}],"totalProperty":86}Ext.onReady(function(){
var reader=new Ext.data.JsonReader({

  
    root: 'root',
    totalProperty: 'totalProperty',
      // the fields config option will internally create an Ext.data.Record
    // constructor that provides mapping for reading the record data objects
    fields: [
        {name: 'name', mapping: 'name'},
    {name: 'age', mapping: 'age', allowBlank: false},
{name: 'sex', mapping: 'sex'},
{name: 'birthday', mapping: 'birthday', type: 'date'},
{name: 'demo', mapping: 'demo'}
    ]
});


     var store=new Ext.data.JsonStore({
      root : 'list',
idProperty : 'name',
totalProperty:'totalProperty',
      url:"GetStudentData",
    fields: [
        {name: 'name',type:"string", mapping: 'name'},
    {name: 'age', type:"int",mapping: 'age', allowBlank: false},
{name: 'sex',type:"string", mapping: 'sex'},
{name: 'birthday', mapping: 'birthday', type: 'date'},
{name: 'demo', type:"string",mapping: 'demo'}
    ]
     });
     
     store.load({params:{start:0,limit:15}});
     
     
  
     
     
   
     
     
     var grid = new Ext.grid.GridPanel({
    store: store,
    renderTo:Ext.getBody(),
    colModel: new Ext.grid.ColumnModel({
        defaults: {
            width: 120,
            sortable: true
        },
       columns:
     [ 
    { id:"name",header: "name", width: 60, sortable: true,dataIndex:"name"},
    { header: "age", width: 150, sortable: true,dataIndex:"age"},
    { header: "sex", width: 100, sortable: true,dataIndex:"sex"},
    { header: "birthday", width: 100, sortable: true,dataIndex:"birthday",xtype:"datecolumn"},
    { header: "demo", width: 100, sortable: true,dataIndex:"demo"}
     ]
    }),
    viewConfig: {
        forceFit: true,//      Return CSS class to apply to rows depending upon data values
        getRowClass: function(record, index) {
            var c = record.get('age');
            if (c < 0) {
                return 'price-fall';
            } else if (c > 0) {
                return 'price-rise';
            }
        }
    },
    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
    width: 600,
    height: 300,
    frame: true,
    title: 'Framed with Row Selection and Horizontal Scrolling',
    iconCls: 'icon-grid'
}); 
})

解决方案 »

  1.   

    firebug没有显示错误信息哈
      

  2.   


    Ext.onReady(function(){
    var reader=new Ext.data.JsonReader({ 
      root: 'root',
      totalProperty: 'totalProperty',
        // the fields config option will internally create an Ext.data.Record
      // constructor that provides mapping for reading the record data objects
      fields: [
      {name: 'name', mapping: 'name'},
      {name: 'age', mapping: 'age', allowBlank: false},
    {name: 'sex', mapping: 'sex'},
    {name: 'birthday', mapping: 'birthday', type: 'date'},
    {name: 'demo', mapping: 'demo'}
      ]
    });
      var store=new Ext.data.JsonStore({
      root : 'root',
    idProperty : 'name',
    totalProperty:'totalProperty',
      url:"GetStudentData",
    fields: [
    {name: 'name',type:"string", mapping: 'name'},
    {name: 'age', type:"int",mapping: 'age', allowBlank: false},
    {name: 'sex',type:"string", mapping: 'sex'},
    {name: 'birthday', mapping: 'birthday', type: 'date'},
    {name: 'demo', type:"string",mapping: 'demo'}
    ]
      });
       
      store.load({params:{start:0,limit:15}});
       
       
      
       
       
       
       
       
      var grid = new Ext.grid.GridPanel({
      store: store,
      renderTo:Ext.getBody(),
      colModel: new Ext.grid.ColumnModel({
      defaults: {
      width: 120,
      sortable: true
      },
      columns:

    { id:"name",header: "name", width: 60, sortable: true,dataIndex:"name"},
    { header: "age", width: 150, sortable: true,dataIndex:"age"},
    { header: "sex", width: 100, sortable: true,dataIndex:"sex"},
    { header: "birthday", width: 100, sortable: true,dataIndex:"birthday",xtype:"datecolumn"},
    { header: "demo", width: 100, sortable: true,dataIndex:"demo"}
    ]
      }),
      viewConfig: {
      forceFit: true,// Return CSS class to apply to rows depending upon data values
      getRowClass: function(record, index) {
      var c = record.get('age');
      if (c < 0) {
      return 'price-fall';
      } else if (c > 0) {
      return 'price-rise';
      }
      }
      },
      sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
      width: 600,
      height: 300,
      frame: true,
      title: 'Framed with Row Selection and Horizontal Scrolling',
      iconCls: 'icon-grid'
    }); 
    })
      

  3.   

    JsonStore包含了JsonReadervar store=new Ext.data.JsonStore({
      root : 'list',  // 改成root:'root',
    idProperty : 'name',
    totalProperty:'totalProperty',
      url:"GetStudentData",
    fields: [
    {name: 'name',type:"string", mapping: 'name'},
    {name: 'age', type:"int",mapping: 'age', allowBlank: false},
    {name: 'sex',type:"string", mapping: 'sex'},
    {name: 'birthday', mapping: 'birthday', type: 'date'},
    {name: 'demo', type:"string",mapping: 'demo'}
    ]
      });