My model seems to be showing the right information for a date (which it's calling a Moment), but when I try to save data to my rails backend, "null" is sent across the wire. I'm using the ActiveModelAdapter, is there anything else I need to do to read/write dates? Thanks!
我的模型似乎显示了日期的正确信息(它正在调用Moment),但是当我尝试将数据保存到我的rails后端时,“null”会通过线路发送。我正在使用ActiveModelAdapter,还有什么我需要做的事情来读/写日期吗?谢谢!
1 个解决方案
#1
1
Are you using Moment.js? The best practice for formatting your dates with Moment is by registering a helper - see the guide here. An addon, e.g. ember-moment, can make this easier.
你在使用Moment.js吗?使用Moment格式化日期的最佳做法是注册帮助程序 - 请参阅此处的指南。插件,例如余烬时刻,可以让这更容易。
Your model itself shouldn't know about Moment - the date attached to your model should just be a Date object. If you've declared dateAttribute: DS.attr("date")
in your model, it should be serialized and transmitted appropriately by Ember Data.
您的模型本身不应该知道Moment - 附加到模型的日期应该只是Date对象。如果您在模型中声明了dateAttribute:DS.attr(“date”),则应该通过Ember Data对其进行序列化和传输。
#1
1
Are you using Moment.js? The best practice for formatting your dates with Moment is by registering a helper - see the guide here. An addon, e.g. ember-moment, can make this easier.
你在使用Moment.js吗?使用Moment格式化日期的最佳做法是注册帮助程序 - 请参阅此处的指南。插件,例如余烬时刻,可以让这更容易。
Your model itself shouldn't know about Moment - the date attached to your model should just be a Date object. If you've declared dateAttribute: DS.attr("date")
in your model, it should be serialized and transmitted appropriately by Ember Data.
您的模型本身不应该知道Moment - 附加到模型的日期应该只是Date对象。如果您在模型中声明了dateAttribute:DS.attr(“date”),则应该通过Ember Data对其进行序列化和传输。