我现在已经有这个问题了一段时间,但我一直在缩小这个问题,我认为我现在已经找到了主要问题。虽然我的JSONstore正确调用了PHP,并且firebug确实从数据库中返回了正确的数据,但它不会显示在我的网格中。
我有一个只有2列日期的网格,以及来自日志的条目。当我取出日志条目时,网格将显示日期正常,当我刚刚从日志创建一个包含静态数据的数组时,它也将在网格中正常显示。我认为我的JSONstore没有正确地从mysql表中解析数据。
我的代码是:
var logStore = new Ext.data.JsonStore({
autoLoad: true,
url: 'inc/interface/config.php?list=messages',
root: 'dates',
idProperty: 'ID',
fields: ['ID', 'ReceivedAt', 'Message'],
listeners: {
loadexception: function() {
console.log('load failed -- arguments: %o', arguments);
}
}
});
var logGrid = new Ext.grid.GridPanel({
region: 'center',
store: logStore,
colModel: new Ext.grid.ColumnModel({
columns: [{
id: 'received',
header: 'Received',
dataIndex: 'ReceivedAt',
width: 250
},{
id: 'message',
header: 'Logs',
dataIndex: 'Message',
width: 750
}]
})
});
它所提取的日志条目的一个例子是:
| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from nfxxxxich-PC.wifi-uhs.osu to 10.xxx.xx.248 |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 248.xxxx.xxx.10.in-addr.arpa. to nxxxxxh-PC.wifi-uhs.osu |
| Apr 9 00:00:02 dh1 dhcpd: DHCPREQUEST for 10.xxx.xxx.248 from 00:x:5c:x:8c:xx (nxxxxh-PC) via 10.xxx.xxx.254 |
| Apr 9 00:00:02 dh1 dhcpd: DHCPACK on 10.X.XX.248 to 00:X:5c:X8c:XX (nXXXich-PC) via 10.193.XX.XXX |
| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from XX.wifi-uhs.XXX to 10.X.X.242 |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 242.X.193.X.in-addr.arpa. to X.wifi-uhs.XXX |
| Apr 9 00:00:02 dh1 dhcpd: DHCPREQUEST for 10.X.X.242 from 00:X:ce:X21:63 (elena) via 10.X.X.254 |
| Apr 9 00:00:02 dh1 dhcpd: DHCPACK on 10.193.XXX.XX to 00:X:ce:X:21:63 (elena) via 10.X.X.254 |
| Apr 9 00:00:02 dh1 dhcpd: Added new forward map from P305-XXX.wifi-uhs.XXX to 10.193.X.X |
| Apr 9 00:00:02 dh1 dhcpd: added reverse map from 21.241.X.X.in-addr.arpa. to P305-XXXX.wifi-uhs.XXX |
日期,dh1和日志条目本身之间有各种不同的字符和制表符。逃避这些角色会有问题吗?我只是不太确定它是如何完成的。任何帮助,将不胜感激。
答案 0 :(得分:0)
您尚未在字段中指定类型和格式。而且我猜你的php json实现不会生成javascript Date
对象。
所以...尝试返回一个unix时间戳并将其用作字段:
fields: [
{name: 'ID', type: 'int'},
{name: 'ReceivedAt', type: 'date', dateFormat: 'Y-m-d H:i:s'},
'Message'
]
您也可以选择在dateFormat
旁边指定type: 'date'
。
有关详细信息,请参阅文档:http://www.sencha.com/deploy/dev/docs/?class=Ext.data.Field
答案 1 :(得分:0)
{"dates":[{"ID":"18","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:03 dh1 dhcpd: added reverse map from 244.xxx.xxx.10.in-addr.arpa. to xxx.wifi-uhs.xxx"},{"ID":"19","ReceivedAt":"2010-07-07 11:37:42","Message":"Apr 9 00:00:03 dh1 dhcpd: DHCPREQUEST for 10.xxx.xxx.244 from 00:xx:f0:xx:d5:xxx (xxx) via xx.x.xxx.254"},{"ID":"20","ReceivedAt":"2010-07-07 11:37:42","Message":" [origin software="rsyslogd" swVersion="3.22.1" x-pid="5222" x-info="http://www.rsyslog.com"] (re)start"},{"ID":"21","ReceivedAt":"2010-07-07 11:37:42","Message":"WARNING: rsyslogd is running in compatibility mode. Automatically generated config directives may interfer with your rsyslog.conf settings. We suggest upgrading your config and adding -c3 as the first rsyslogd option."},{"ID":"22","ReceivedAt":"2010-07-07 11:37:42","Message":"the last error occured in /etc/rsyslog.conf, line 38"},{"ID":"23","ReceivedAt":"2010-07-07 11:37:42","Message":"warning: selector line without actions will be discarded"},{"ID":"24","ReceivedAt":"2010-07-07 11:37:42","Message":"CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'. [try http://www.rsyslog.com/e/2123 ]"},{"ID":"25","ReceivedAt":"2010-07-07 11:37:42","Message":"Warning: backward compatibility layer added to following directive to rsyslog.conf: ModLoad imuxsock"}]}
实际上我发现了问题,而不是我的代码。我限制我的PHP仅提取19条记录并且它有效,它在第20条记录中,我得到一种不同类型的日志,它在我的网格上混乱,什么都不会显示。我认为它与日志中的特殊字符有关。
无论哪种方式,Rsyslog都是一个错误,我正在使用它将这些转储到mysql中。我不确定如何通过php / extjs修复它。