我一直在努力让一个使用 EmberJS 和 Rails 运行的简单场景。
这是我所拥有的(结合JS):
App = Ember.Application.create
LOG_TRANSITIONS: true
App.Post = DS.Model.extend
title: DS.attr 'string'
description: DS.attr 'string'
App.StreamRoute = Ember.Route.extend
setupController: (controller, model) ->
controller.set 'posts', model
model: -> @store.find('post')
App.Router.map ->
@.route 'stream', path: '/'
以下是模板内容:
{{#each posts}}
{{title}}
{{/each}}
这是/posts
JSON 的Post.all
(也许这是错误的?):
{
"posts": [
{
"posts": {
"created_at": "2013-08-15T23:48:54+01:00",
"description": "A few months ago I helped develop these posters for research that our UX team had gathered to create personas for our customers to show who they are and who actually uses our product.",
"id": 7,
"likes_count": 1,
"slug": "16ErQ",
"thumb": {
"url": "\/posts\/1\/16ErQ\/man.png",
"medium": {
"url": "\/posts\/1\/16ErQ\/medium_man.png"
}
},
"title": "Persona Project",
"updated_at": "2013-08-15T23:48:54+01:00",
"user_id": 1,
"views_count": 0
}
},
{
"posts": {
"created_at": "2013-08-16T15:47:03+01:00",
"description": "Just a little something.",
"id": 8,
"likes_count": 0,
"slug": "VYIvn",
"thumb": {
"url": "\/posts\/2\/VYIvn\/face.jpg",
"medium": {
"url": "\/posts\/2\/VYIvn\/medium_face.jpg"
}
},
"title": "Face",
"updated_at": "2013-08-16T15:47:03+01:00",
"user_id": 2,
"views_count": 0
}
},
{
"posts": {
"created_at": "2013-08-16T17:03:10+01:00",
"description": "Some people say, he's still running.",
"id": 9,
"likes_count": 2,
"slug": "hQBnt",
"thumb": {
"url": "\/posts\/1\/hQBnt\/run.jpg",
"medium": {
"url": "\/posts\/1\/hQBnt\/medium_run.jpg"
}
},
"title": "Run, Forest, run.",
"updated_at": "2013-08-23T23:44:19+01:00",
"user_id": 1,
"views_count": 0
}
}
]
}
我认为这很好,但它不太好用,当我运行它时,我得到 3 个帖子结果(有多少),但列都包含空值:http ://c.daryl.im /RTzO
如您所见,我也有这个错误。有任何想法吗?