我有以下簡單的HTML。它在使用ExtJS 4時工作,但在使用ExtJS 4.2時不起作用。從webserivce Json商店在ExtJS 4.0但不是4.2
在這兩種情況下,Web服務都被調用,但是當使用ExtJS 4.2時,store.data
爲空。
我猜這是問題(這裏的東西是不是在ExtJS的4.2支持,但我不知道是什麼):
Ext.define('Ext.AspWebAjaxProxy', {
extend: 'Ext.data.proxy.Ajax',
require: 'Ext.data',
buildRequest: function (operation) {
var params = Ext.applyIf(operation.params || {}, this.extraParams || {}),
request;
params = Ext.applyIf(params, this.getParams(params, operation));
if (operation.id && !params.id) {
params.id = operation.id;
}
params = Ext.JSON.encode(params);
request = Ext.create('Ext.data.Request', {
params: params,
action: operation.action,
records: operation.records,
operation: operation,
url: operation.url
});
request.url = this.buildUrl(request);
operation.request = request;
return request;
}
});
這是完整的代碼:
<body>
<div id="ext-grid">
</div>
<script type="text/javascript">
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.panel.*',
'Ext.layout.container.Border'
]);
Ext.define('Ext.AspWebAjaxProxy', {
extend: 'Ext.data.proxy.Ajax',
require: 'Ext.data',
buildRequest: function (operation) {
var params = Ext.applyIf(operation.params || {}, this.extraParams || {}),
request;
params = Ext.applyIf(params, this.getParams(params, operation));
if (operation.id && !params.id) {
params.id = operation.id;
}
params = Ext.JSON.encode(params);
request = Ext.create('Ext.data.Request', {
params: params,
action: operation.action,
records: operation.records,
operation: operation,
url: operation.url
});
request.url = this.buildUrl(request);
operation.request = request;
return request;
}
});
Ext.onReady(function() {
Ext.define('Actors', {
extend: 'Ext.data.Model',
fields: ['FirstName', 'LastName', 'EmailAddress', 'Salary']
});
store = new Ext.data.Store(
{
proxy: new Ext.AspWebAjaxProxy({
url: 'service.asmx/LoadRecords',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
model: 'Actors',
root: 'd'
},
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
})
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{ text: 'FirstName', dataIndex: 'FirstName', width: 280, sortable: true },
{ text: 'LastName', dataIndex: 'LastName', sortable: true },
{ text: 'EmailAddress', dataIndex: 'EmailAddress', width: 150, sortable: true },
{ text: 'Salary', dataIndex: 'Salary', sortable: true }
],
renderTo: 'ext-grid'
});
store.load();
});
</script>
</body>
這是JSON:
{
"d": [
{
"__type": "CrystalBall.service+Record",
"FirstName": "Palash",
"LastName": "Debnath",
"EmailAddress": "[email protected]",
"Salary": 100
},
{
"__type": "CrystalBall.service+Record",
"FirstName": "Pritam",
"LastName": "Debnath",
"EmailAddress": "[email protected]",
"Salary": 200
}
]
}
你回來的JSON非常標準,它工作。請求的樣子應該如何?如果你能詳細說明這一點,我可以幫助你更好。 –
我解決了這個問題,我刪除了ActionMethod並將GET服務調用爲web服務。 – Alophind