0

遵循 Emberjs.com (http://emberjs.com/guides/outlets/) 上的“Outlets”指南后,我无法在帖子(子/单数)模板中显示帖子的标题和正文。你们中有人遇到过吗?这是纲要:

# PostsTemplate
{{#each post in controller}}
  <h1><a {{action showPost post href=true}}>{{post.title}}</a></h1>
  <div>{{post.body}}</div>   <------ title and body show up correctly here
{{/each}}

# PostTemplate
<h1>{{title}}</h1>  <---- but title and body are EMPTY here  
<div class="body">
  {{body}}
</div>
{{outlet}}

# Router
App.Router = Ember.Router.extend({
  root: Ember.Route.extend({
    index: Ember.Route.extend({
      route: '/',
      redirectsTo: 'posts'
    }),
    posts: Ember.Route.extend({
      route: '/posts',
      showPost: Ember.Route.transitionTo('post'),
      connectOutlets: function(router) {
        router.get('applicationController').connectOutlet('posts', App.Post.find());
      }
    }),
    post: Ember.Route.extend({
      route: '/posts/:post_id',
      connectOutlets: function(router, post) {
        console.log(post);    <------------------ This tells me the post has the write attributes.
        router.get('applicationController').connectOutlet('post', post); #This post does not show up in PostTemplate above!
      }
     })
 });

当我运行 console.log(post) 并检查帖子时,我发现我有以下内容:

Class = {
 id: "1",
 _data:
  { 
    attributes:
    {
      body: "a",
      title: "a" 
    }
  },
  title: null,
  body: null
 }

任何人都知道为什么我没有看到标题或正文属性出现在视图中?

ps Post 模型是一个 Ember 数据模型,可以从 Rails 应用程序中正确检索 id 为 1 的 Post。

4

1 回答 1

1

I believe you can use {{content.title}} and {{content.body}} since your Post model should be set to the content of the postController. An easy way to debug this within the view is to put {{content}} in the view which will render the type of model that the item is (such as App.Post).

于 2012-12-03T13:14:08.240 回答