[英]Polymer 1.0 - Increment through nested array on template bind.
I am working on a polymer element which receives a json array from a web service. 我正在研究聚合物元素,该元素从Web服务接收json数组。 In the component there is a template that should iterate over the array to display one of array values. 在组件中,有一个模板,该模板应在数组上进行迭代以显示数组值之一。
The following code displays one of the nested arrays. 下面的代码显示嵌套数组之一。
<template is="dom-repeat" items="{{response.0.sentence}}">
<div style="display: inline; postition: realative;">
<span>{{item.word}}></span>
</div>
</template>
Here is an example of the data the webservice returns 这是Web服务返回的数据的示例
[
{
"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"
}
]
}]
Current Output: He is it he 当前输出:他是他
What I need to do is iterate through every sentence in the object and display its word property. 我需要做的是遍历对象中的每个句子并显示其word属性。 Which should be able to do by incrementing the 0 in items="{{response.0.sentence}}" 应该可以通过在items =“ {{{response.0.sentence}}}”中将0递增来完成
Wanted Output: He is it he they it polymer red 想要的输出:他是他将其聚合成红色
I looked at several potential solutions such as creating the binding by the following, but had no luck. 我研究了几种潜在的解决方案,例如通过以下方法创建绑定,但是没有运气。
<template is="dom-repeat" items="{{response}}" index-as="i">
<div style="display: inline; postition: realative;">
<span>{{item.i.sentence.word}}></span>
</div>
</template>
My next guess is to create some sort of computed value, but I have had trouble finding a way to implement that within the binding or I am missing something obvious when stepping through nested arrays. 我的下一个猜测是创建某种计算值,但是在查找绑定中实现该方法时遇到了麻烦,或者在单步执行嵌套数组时缺少明显的东西。
Any help would be appreciated. 任何帮助,将不胜感激。
Use a nested dom-repeat
: 使用嵌套的dom-repeat
:
<template is="dom-repeat" items="[[response]]">
<template is="dom-repeat" items="[[item.sentence]]">
<span>[[item.word]]</span>
</template>
</template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.