Javascript 关系在ember fixture adapter中工作吗?

Javascript 关系在ember fixture adapter中工作吗?,javascript,ember.js,Javascript,Ember.js,我不确定我在这里做错了什么,只是尝试使用fixture适配器获得一对多关系来处理余烬数据。在jsbin上: 我在html中没有看到来自{{each}}循环的任何输出 js: html: JS-Bin 余烬最新jsbin {{outlet}} 索引内容: {{{#主题中的每个主题} {{id} {{{#每个职位中的每个职位} {{body}} {{/每个}} {{/每个}} 默认情况下,Fixture适配器不支持嵌入关系。实现这一点的最简单方法是将关系设置为异步,并将它们添加到post的fi

我不确定我在这里做错了什么,只是尝试使用fixture适配器获得一对多关系来处理余烬数据。在jsbin上:

我在html中没有看到来自{{each}}循环的任何输出

js:

html:


JS-Bin
余烬最新jsbin
{{outlet}}
索引内容:
    {{{#主题中的每个主题}
  • {{id}
  • {{{#每个职位中的每个职位} {{body}} {{/每个}} {{/每个}}

默认情况下,Fixture适配器不支持嵌入关系。实现这一点的最简单方法是将关系设置为异步,并将它们添加到post的fixture中

App.Post = DS.Model.extend({
  body: DS.attr('string'),
  topic: DS.belongsTo('topic', {async: true})
});

App.Topic = DS.Model.extend({
  posts: DS.hasMany('post', {async: true})
});

App.Topic.FIXTURES = [
  {
    id: 1,
    posts: [1]
  }
];

App.Post.FIXTURES = [
  {
    id: 1,
    body: 'hey i am a post',
    topic: 1
  }
];
这是您的jsbin及其设置

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
  <script src="http://code.jquery.com/jquery-2.0.2.js"></script>
  <script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
  <script src="http://builds.emberjs.com/ember-latest.js"></script>
    <script src="http://builds.emberjs.com/ember-data-latest.js"></script>

</head>
<body>
  <script type="text/x-handlebars" data-template-name="application">
    <h1>ember-latest jsbin</h1>
    {{outlet}}
  </script>
  <script type="text/x-handlebars" data-template-name="topics">
    <h2>Index Content:</h2>
    <ul>
      {{#each topic in topics}}
        <li>{{id}}</li>
        {{#each post in posts}}
          {{body}}
        {{/each}}
      {{/each}}
    </ul>
  </script>
</body>
</html>
App.Post = DS.Model.extend({
  body: DS.attr('string'),
  topic: DS.belongsTo('topic', {async: true})
});

App.Topic = DS.Model.extend({
  posts: DS.hasMany('post', {async: true})
});

App.Topic.FIXTURES = [
  {
    id: 1,
    posts: [1]
  }
];

App.Post.FIXTURES = [
  {
    id: 1,
    body: 'hey i am a post',
    topic: 1
  }
];