admin管理员组文章数量:1356808
I'm trying to save an object containing a date attribute in Ember.js.
After calling createRecord() on the store, the new object is represented on the page, but the date attribute disappears from the page upon calling save(). All other attribute types on the model do not exhibit this appear-then-disappear behavior. Here is some example code:
App = Ember.Application.create()
App.IndexRoute = Ember.Route.extend
model: () -> @store.find "post"
App.Post = DS.Model.extend
time: DS.attr "date"
body: DS.attr "string"
App.IndexController = Ember.ArrayController.extend
actions:
createPost: () ->
body = @get 'newBody'
post = @store.createRecord 'post',
body: body
time: Date.now()
@set 'newBody', ''
post.save()
App.Post.FIXTURES = [
id: 1
time: new Date("2013-9-30")
body: "fixture post"
]
Please see this jsfiddle for a demonstration.
I'm trying to save an object containing a date attribute in Ember.js.
After calling createRecord() on the store, the new object is represented on the page, but the date attribute disappears from the page upon calling save(). All other attribute types on the model do not exhibit this appear-then-disappear behavior. Here is some example code:
App = Ember.Application.create()
App.IndexRoute = Ember.Route.extend
model: () -> @store.find "post"
App.Post = DS.Model.extend
time: DS.attr "date"
body: DS.attr "string"
App.IndexController = Ember.ArrayController.extend
actions:
createPost: () ->
body = @get 'newBody'
post = @store.createRecord 'post',
body: body
time: Date.now()
@set 'newBody', ''
post.save()
App.Post.FIXTURES = [
id: 1
time: new Date("2013-9-30")
body: "fixture post"
]
Please see this jsfiddle for a demonstration.
Share Improve this question edited Oct 12, 2013 at 1:14 Jordan asked Oct 12, 2013 at 0:18 JordanJordan 231 silver badge5 bronze badges1 Answer
Reset to default 11Instead of using Date.now()
you should use new Date()
.
Date.now()
returns an integer which seems to give Ember problems. new Date()
returns an actual Date
object which Ember can deal with. Here's a slightly modified jsfiddle : http://jsfiddle/AJRts/
本文标签: javascriptHow do I save a model with attribute of type 39date39 in EmberjsStack Overflow
版权声明:本文标题:javascript - How do I save a model with attribute of type 'date' in Ember.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744038582a2580240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论