使用 Firefox 显示 YUI 数据表和日期
我正在使用通过 JSON 加载的数据表,日期如下:2010-06-03 对于 Opera 和 Chrome,我的正确日期显示为 06/03/2010。使用 Firefox Windows(即使在安全模式下,没有任何插件),我得到 NaN/NaN/NaN。如果我使用调试控制台,我会看到有效日期,但在 Firefox Windows 中我会看到“无效日期”。 另外,有了 Firefox Mac 和大量插件,我们就有了有效日期!
这是日期列的设置
oColumn['editor'] =
new YAHOO.widget.DateCellEditor({asyncSubmitter:UpdateRowData});
oColumn['formatter'] = YAHOO.widget.DataTable.formatDate;
oField['parser'] = 'date';
谢谢,
塞德里克
I am using a datatable loaded via JSON with date like this : 2010-06-03
With Opera and Chrome I have the correct date displayed as 06/03/2010. With Firefox Windows (even in safe mode, without any plug-in), I get a NaN/NaN/NaN. If I use the debug console, I see a valid date, but in Firefox Windows I can see a "Invalid date".
Bonus, with Firefox Mac awith a ton of plug-ins, we have the valid date!
Here is the setting of the date column
oColumn['editor'] =
new YAHOO.widget.DateCellEditor({asyncSubmitter:UpdateRowData});
oColumn['formatter'] = YAHOO.widget.DataTable.formatDate;
oField['parser'] = 'date';
Thanks,
Cédric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
结果“2010-06-03”没有返回有效的 Date 对象(至少在 FF/Win 中)。为了跨浏览器兼容性,请确保您的值采用 Date 构造函数可接受的格式:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/日期
Turns out that "2010-06-03" does not return an valid Date object (at least in FF/Win). For cross-browser compatibility, be sure your value is in a format acceptable to the Date constructor:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date
Jenny 的参考很好,但如果您不想深入研究,您应该将:
“YYYY,MM,DD”
传递到 YUI 解析器中,以使其在 FF/Win 以及 Chrome 中工作。
Jenny's reference is good but in case you don't want to dig, you should pass:
"YYYY,MM,DD"
into the YUI parser to get it to work in FF/Win as well as Chrome.
根据您的情况,解决此问题的另一种方法是在“JSON”数据中包含实际的日期构造函数。一旦执行此操作,它就不再是标准 JSON,您需要在浏览器上对其进行评估。
例如,
好处是不再需要在浏览器上解析数据,因为数据已经是日期对象。
缺点是您不再将有效的 JSON 从服务器发送到客户端浏览器。
Depending on your situation, another way to solve this is to include an actual date constructor in your "JSON" data. Once you do so, it's no longer standard JSON and you'll need to eval it on the browser.
Eg
The benefit is no longer any need to parse the data on the browser since the datum is already a date object.
The downside is that you're no longer sending valid JSON from your server to your client browsers.