ExtJS:以单独的格式提交日期
我正在使用 ExtJS v4.0。
维护客户端和服务器端之间的日期格式确实令人困惑。
用户想要自己的输入格式,但服务器通常要求提交是一种标准格式。
它应该是 ExtJS 中的内置实现,但事实并非如此。
我已经阅读了有关此问题的一些解决方案,但他们只尝试解决 DateField 格式(通过创建特殊的 DateField 插件或扩展 SubmitAction)。
我正在寻找一个全局解决方案来格式化所有可以提交的日期(网格/商店编写器、表单/日期字段等)。
因此,日期可能根据区域设置具有自定义显示格式,但它们将以一种标准格式提交(例如 yyyy-mm-dd)。
对于这个问题有什么建议吗?
非常感谢。
I'm using ExtJS v4.0.
Maintaining date format between client and server side is really confusing.
Users want their own input formats, but the server usually requires the submission to be one standard format.
It should be a built in implementation in ExtJS but it's not.
I have read some solutions regarding to this issue but they only try to solve DateField formatting (by creating special DateField plugin or extending SubmitAction).
I'm looking for a global solution to format all dates which can be submitted (grid/store writer, form/datefield, etc).
So, dates may have custom display format according to locale but they will be submitted in one standard format (e.g. yyyy-mm-dd).
Any suggestion for this problem?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我从使用版本 4.2.1 的文档中找到的唯一有效答案
This was the only working answer that I found from documentation using version 4.2.1
我不知道任何通用的、在代码中实现一次的解决方案。但是您可以编写一个函数来迭代模式对象。有点像它在 < 末尾谈论 code>Ext.Date 文档中的对象介绍。您肯定需要添加更多模式,并且必须在需要的地方单独实现它,例如:对于商店编写器,您可以在
beforesync
事件中使用它,但对于日期字段,您可以将其作为验证器函数。我在不同的地方使用了这样的函数,这样用户就不会被绑定到特定的日期模式,该函数:我正在谈论的文档的具体引用是这样的:
就像我说的,您必须添加到他们的模式对象中,并且实现会根据您使用它的位置而有所不同,但这就是我的做法。
I don't know any universal, implement once in your code, kind of solution to this. But you could write a function that would iterate through a patterns object. Kind of like it talks about at the end of the
Ext.Date
object intro in the docs. You would definitely have to add more patterns and you have to implement it individually where you wanted it, e.g.: For a store writer you could use it in thebeforesync
event but for a datefield you would put it as a validator function. I used a function like this in different places so that users wouldn't be tied to a specific date pattern, the function:The specific quote from the docs I am talking about is this:
Like I said, you would have to add to their patterns object and implementation would vary depending on where you're using it, but that's how I do it.