2011-09-16 44 views
0

我在mysql中一個簡單的數據,並要填充的ExtJS的柵格數據如何綁定的JSON ExtJS的電網

我的代碼

 

Ext.onReady(function(){ 

    var proxy=new Ext.data.HttpProxy( {url:'connectextjs.php'}); 

      var reader=new Ext.data.JsonReader(
      [ 
       {name: 'Employee_ID', mapping: 'Employee_ID'}, 
       {name: 'Department_ID'},   
       {name: 'Name'}, 
       {name: 'Email'}, 

      ] 
     ) 

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

    store.load(); 


    // create the grid 
    var grid = new Ext.grid.GridPanel({ 
     store: store, 
     columns: [ 
      {header: "Employee_ID", width: 90, dataIndex: 'Employee_ID', sortable: true}, 
      {header: "Department_ID", width: 90, dataIndex: 'Department_ID', sortable: true}, 
      {header: "Name", width: 90, dataIndex: 'Name', sortable: true}, 
      {header: "Email", width: 200, dataIndex: 'Email', sortable: true}, 

     ], 
     renderTo:'example-grid', 
     width:540, 
     height:200 
    }); 

}); 

我的問題是我無法加載數據在網格上。請幫助我,我是新來的ExtJS

感謝

+0

是什麼'connectextjs.php'返回? –

回答

0

connectextjs.php應的Employee_ID,Deaprtment_ID,姓名和電子郵件的init返回JSON格式化數據。南明公約應嚴格遵守。

0

您可以使用此方法設置網格的數據。

  1. 首先,分配一個ID,你的網格,就像這樣:

    itemId : 'myGrid'; 
    
  2. 得到JSON從您的JSON調用進行加載,這樣的:

    Ext.Ajax.request({ 
    url : 'connectextjs.php', 
    
    params : { 
    
    yourParam : 'yourParameters' 
    
    }, 
    
    // --> success simply means your action has no errors 
    
    success : function (conn, response, options, eOpts){ 
    
        var jsonResults = Ext.JSON.decode(conn.responseText); 
    
    
        // --> Now that you have your JsonResults Its time to set it to your grid 
        me.getView().down('#myGrid').setStore(jsonResults); 
    
    } 
    
    });