[英]How to serialise ember date?
I'm new to ember and I want to post a new record, So I did something like: 我是ember的新手,我想发布一个新记录,所以我做了类似的事情:
App.AdminController = Em.Controller.extend
submit: ->
post = App.Post.createRecord()
post.set('author', $('#author').val())
post.set('title', $('#title').val())
post.set('intro', $('#intro').val())
post.set('description', $('#description').val())
post.set('publishedAt', new Date())
post.get('store').commit()
Everything works like a charm, except the publisedAt
attribute e in post
request json file is null 除
post
请求json文件中的publisedAt
属性e为null之外,其他所有内容都像魅力一样工作
I think the problem is due to that I may not serialise it correctly, any idea? 我认为问题是由于我可能无法正确序列化它,对吗?
update the model: 更新模型:
App.Post = DS.Model.extend
title: DS.attr('string')
author: DS.attr('string')
intro: DS.attr('string')
description: DS.attr('string')
publishedat:DS.attr('date')
尝试在Date对象上使用JSON.stringify:
post.set('publishedAt', JSON.stringify(new Date()))
For some reason, you can't invoke new Date() inside the .set method. 由于某些原因,您无法在.set方法内调用new Date()。 This should work:
这应该工作:
var d = new Date();
post.set('publishedAt', d);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.