【发布时间】:2011-09-14 19:05:51
【问题描述】:
我正在尝试使用使用代理和定义的模型和读取器的数据存储来填充网格。类似的商店没有同样的问题,但有一个。
型号
Ext.define('DrillDescriptionGridModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'sentTime', type: 'string'},
{name: 'sDescription', type: 'string'},
{name: 'receivedTime', type: 'string'},
{name: 'seconds', type: 'number'},
{name: 'formatted', type: 'string'},
{name: 'alertPhone', type: 'string'},
{name: 'alertEmail', type: 'string'}
]
});
读者
var DrillDescriptionReader = Ext.create('Ext.data.JsonReader', {
type: 'json',
model: 'DrillDescriptionGridModel',
root: 'data'
});
商店
DrillDescriptionStore = Ext.create('Ext.data.Store', {
model: 'DrillDescriptionGridModel',
autoLoad: false,
proxy: {
type: 'ajax',
url: '/inc/ajax/Monitors.php',
actionMethods: 'POST',
reader: DrillDescriptionReader
},
listeners: {
load: function() {
console.log(this.getAt(0));
DrillDescriptionPanel.show();
}
}
});
代理返回一个json字符串
{"data":[{"sDescription":"Status Normal","sentTime":"12:00:00 am","receivedTime":"12:00:01 am","seconds":"2","formatted":"2 seconds","alertPhone":"","alertEmail":""}, [...]
负载监听器中的console.log显示
Ext.Class.c.m
data: Object
alertEmail: ""
alertPhone: ""
formatted: "2 seconds"
receivedTime: "12:00:01 am"
seconds: 2
sentTime: "12:00:00 am"
__proto__: Object
[...]
raw: Object
alertEmail: ""
alertPhone: ""
formatted: "2 seconds"
receivedTime: "12:00:01 am"
sDescription: "Status Normal"
seconds: 2
sentTime: "12:00:00 am"
__proto__: Object
[...]
任何人都知道为什么 sDescription 字段会映射到原始对象中,而不是数据对象中,或者发现代码中的错误?任何帮助将不胜感激。谢谢。
【问题讨论】:
-
我已经在 Linux 上的 Chromium 中使用 Ext 4.0.2a 测试了您的代码,并且也可以在数据对象中看到 sDescription。您使用的是哪个版本的 ExtJS?
-
我用的是 4.0.2(不是 a),在 Mac 上用 Chrome 和 FF6.0.2 测试,在 Windows 环境下用 IE8 测试,结果相同。
-
您的代码在 4.0.2 中也可以按预期工作 - 在 Linux 和 Windows 上的 Chromium 中。现在我不知道是什么导致了你的问题。