我有以下简单的 HTML。它在使用 ExtJS 4 时有效,但在使用 ExtJS 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": "palash@yahoo.com",
"Salary": 100
},
{
"__type": "CrystalBall.service+Record",
"FirstName": "Pritam",
"LastName": "Debnath",
"EmailAddress": "pritam@yahoo.com",
"Salary": 200
}
]
}