Polymer 1.0 - 通过模板绑定上的嵌套数组递增。

Polymer 1.0 - Increment through nested array on template bind.

我正在研究从网络服务接收 json 数组的聚合物元素。在组件中有一个模板应该遍历数组以显示数组值之一。

以下代码显示嵌套数组之一。

    <template is="dom-repeat" items="{{response.0.sentence}}">
     <div style="display: inline; postition: realative;">
       <span>{{item.word}}></span>
     </div>
   </template>

这里是webservice的数据示例returns

    [
{
    "sentence": [
        {
            "word": "He",
            "Color": "Black"   
        },
        {
            "word": "is",
            "color": "purple"   
        },
        {
            "word": "it",
            "color": "green"
        },
        {
            "word": "he",
            "color": "red"
        }
    ]
},
{
    "sentence": [
                {
            "word": "they",
            "Color": "Black"   
        },
        {
            "word": "it",
            "color": "purple"   
        },
        {
            "word": "polymer",
            "color": "green"
        },
        {
            "word": "red",
            "color": "green"
        }
    ]
}]

当前输出:他就是他

我需要做的是遍历对象中的每个句子并显示它的单词属性。这应该可以通过增加 items="{{response.0.sentence}}"

中的 0 来实现

想要的输出:他是他他们是聚合物红色

我查看了几种可能的解决方案,例如通过以下方式创建绑定,但没有成功。

   <template is="dom-repeat" items="{{response}}" index-as="i">
     <div style="display: inline; postition: realative;">
       <span>{{item.i.sentence.word}}></span>
     </div>
   </template>

我的下一个猜测是创建某种计算值,但我很难找到在绑定中实现该值的方法,或者我在单步执行嵌套数组时遗漏了一些明显的东西。

如有任何帮助,我们将不胜感激。

使用嵌套 dom-repeat:

 <template is="dom-repeat" items="[[response]]">
  <template is="dom-repeat" items="[[item.sentence]]">
    <span>[[item.word]]</span>
  </template>
 </template>