Polymer 1.0:嵌套的dom-repeat模板无法显示子对象的内容

Ham*_*nit 3 polymer polymer-1.0

我想在帖子数据中显示一个对象内容(评论)(使用firebase-collection):这是firebase中帖子的结构:

"Publication" : {
       "date":"22-06-2015",
 "content" : "post example",
 "comments": {
  //a post has too many comments on it
  }
}
Run Code Online (Sandbox Code Playgroud)

我的目标是添加另一个dom-repeat来显示评论,但我看不到任何东西.这是代码示例(第一个模板正如我提到的那样正常工作)

<template is="dom-repeat" items="{{posts}}" as="post">
      <!-- Content here is appearing correctly --> 
          <template is="dom-repeat" items="{{post.comments}}" as="commentaire">
               <span>{{commentaire.date}}</span>
           </template>
</tempalte>
Run Code Online (Sandbox Code Playgroud)

我按照Polymer Migration文档但没有结果,如果有任何解决方案我会感激不尽.

小智 5

我认为你的comments属性需要是一个数组才能正确绑定.

  • 你可以写一个像这样的过滤器:arrayify:function(obj){return Object.keys(obj).map(function(k){return obj [k];})}`然后绑定到`items ="{{ arrayify(post.comments)}}"`. (4认同)