Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript EmberJS不会自动显示视图中上下文对象的属性_Javascript_Ember.js_Ember Data - Fatal编程技术网

Javascript EmberJS不会自动显示视图中上下文对象的属性

Javascript EmberJS不会自动显示视图中上下文对象的属性,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,在遵循Emberjs.com上的“门店”指南之后(http://emberjs.com/guides/outlets/)我无法在帖子(子/单数)模板中显示帖子的标题和正文。你们有谁碰到过这个吗?下面是详细情况: # PostsTemplate {{#each post in controller}} <h1><a {{action showPost post href=true}}>{{post.title}}</a></h1> <d

在遵循Emberjs.com上的“门店”指南之后(http://emberjs.com/guides/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!
      }
     })
 });
有人知道为什么我没有看到标题或身体属性出现在视图中吗


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

我相信您可以使用{{content.title}和{{content.body},因为您的Post模型应该设置为postController的内容。在视图中调试此项的一个简单方法是将{{content}}放在视图中,该视图将呈现该项所属的模型类型(例如App.Post)。

Nice!我试试看,然后再报告!
Class = {
 id: "1",
 _data:
  { 
    attributes:
    {
      body: "a",
      title: "a" 
    }
  },
  title: null,
  body: null
 }