2013-04-15 61 views
1

早上好, 當我試圖從我的web服務填充我的網格面板時,出現了一些問題,結果是一個空網格,感謝您的提前。從商店填充網格面板不起作用EXTJS 4.2

// Create store 

var myStore = new Ext.data.JsonStore({ 
    proxy: new Ext.data.HttpProxy({ 
     url: 'Service.asmx/GetPeople', 
     headers: { 
      'Content-type': 'application/json' 
     } 
    }), 
    root: 'd', 
    id: 'Id', 
    fields: ['Id', 'FistName', 'LastName', 'BirthDate'], 
    autoLoad: true 
}); 

//Create grid to display data from store 

var gridTest = new Ext.grid.Panel({ 
    store: myStore, // Our store 
    renderTo: Ext.getBody(), 
    forceFit: true, 
    columns: [ // Grid columns 
     { xtype: 'gridcolumn', width: 100, text: 'Id', dataIndex: 'Id', flex: 1 }, 
     { xtype: 'gridcolumn', width: 100, text: 'Nom', dataIndex: 'FirstName', flex: 1 }, 
     { xtype: 'gridcolumn', width: 100, text: 'Mail', dataIndex: 'LastName', flex: 1 }, 
     { xtype: 'gridcolumn', width: 100, text: 'Phone', dataIndex: 'BirthDate', flex: 1 }  
    ] 
}); 

,這是我視:

Ext.create('Ext.container.Viewport', { 
    layout: "border", 
    items: [{ 
     region: "north", 
     height: 50, 
     title: "Nord" 
    }, { 
     region: "south", 
     height: 200, 
     title: "sud", 
     bodyStyle: 'background: #fffff;', 
     border: false 
    }, { 
     region: "center", 
     title: "centre", 
     bodyStyle: 'background: #00000;', 
     border: false, 
     items: gridTest          
    }, { 
     region: "west", 
     width: 100, 
     title: "ouest" 
    }, { 
     region: "east", 
     width: 100, 
     title: "est" 
    }] 
}); 

,這是響應已從Firebug的Mozilla Firefox瀏覽器:

{"d": [{ 
    "__type":"WebService4ExtJS.Model.Person", 
    "Id":0, 
    "FirstName":"sami", 
    "LastName":"[email protected]", 
    "BirthDate":"23188219" 
    }, { 
    "__type":"WebService4ExtJS.Model.Person", 
    "Id":1,"FirstName":"admin", 
    "LastName":"[email protected]", 
    "BirthDate":"1111111" 
    }, { 
    "__type":"WebService4ExtJS.Model.Person", 
    "Id":2, 
    "FirstName":"user", 
    "LastName":"[email protected]", 
    "BirthDate":"2222222" 
    }] 
} 
+0

你從哪裏得到你的代理配置?看看例子的文檔。 – dbrin

+0

我試圖用EXTJS版本2.2來執行這些腳本,但是當我更改爲新版本時,我發現了一個問題,我無法使用較新版本的ExtJS 4.2,thx爲所有幫助 –

+0

API發生了相當大的變化,您將不得不改變你的代碼以適應。看看正確的方式來做你正在做的事情的例子。 – dbrin

回答

0

您的店鋪讀者沒有定義:

reader: { 
    type: 'json', 
    root: 'd', 
    idProperty: 'Id' 
} 

你可以找到工作代碼here

還有一個小錯誤:在字段數組中,你寫了FistName而不是FirstName

+0

謝謝Darin Kolev, –

+0

謝謝Darin Kolev,但是當我使用帶有Web服務的Store(Visual Studio 2010)時,那會導致一個空網格。你也可以找到我的project_code:[link](http://www.4shared.com/rar/JjhaIq6s/WebService4ExtJS_local.html?) –