简体   繁体   English

在Emberjs中使用每个显示嵌套的json数据

[英]displaying nested json data using each in Emberjs

I have successfully displayed JSON objects unto my template thanks the answer on my previous stackoverflow post setting data from route to controller error in Emberjs 我已经成功地在模板中显示了JSON对象,这要归功于我以前的stackoverflow发布设置数据,从Emberjs中的路由到控制器错误

Now, I am trying to display a nested JSON data objects to my template using the {{#each}} helper. 现在,我正在尝试使用{{#each}}帮助器将嵌套的JSON数据对象显示到模板中。

here is my code: http://screencast.com/t/3fhpckr4E 这是我的代码: http : //screencast.com/t/3fhpckr4E

It doesn't give me any errors on my dev console and also it just gives me blank text. 它不会在我的开发控制台上给我任何错误,也只会给我空白文本。 I've also wrote the code in different ways but still no luck.. 我也以不同的方式编写了代码,但还是没有运气。

any feedback would be appreciated 对于任何反馈,我们都表示感谢

thanks, 谢谢,

You can do this in your template as follows: 您可以在模板中执行以下操作:

<script type="text/x-handlebars" data-template-name="index">
  <ul>
  {{#each item in model}}
    <li>{{item.description}}</li>
    <ul>
    {{#each childItem in item.items}}
      <li>{{childItem.title}}</li>
    {{/each}}
    </ul>
  {{/each}}
  </ul>
</script>

Working solution here 这里的工作解决方案

The problem with what you are doing is that there is no such thing as data.items.items. 您正在做的问题是没有data.items.items之类的东西。 Each item in the data.items array has its own items property... data.items数组中的每个项目都有其自己的items属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM