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/