Polymer 确定最后一项 on dom-repeat items
Polymer determine the last item on dom-repeat items
我正在尝试从字符串数组创建面包屑。
我有一个名为 taxonomy
的数组 属性,它看起来像 ["categories", "clothing", "men", "suits"]
。像这样使用 dom-repeat
:
<template is="dom-repeat" items="{{taxonomy}}" id="breadcrumbs">
<span>{{item}}</span><span hidden$="[[computeSpanHidden]]"> > </span>
</template>
生成的视图如下所示:
类别>服装>男装>套装>
我想要删除最后一个 > 得到这样的东西:
类别>服装>男装>套装
我已经尝试通过绑定到我想隐藏的跨度的隐藏属性来做到这一点,但我被卡住了。不完整的 computeSpanHidden
函数如下所示:
computeSpanHidden: function(){
if(this.taxonomy.slice(-1)[0] == /**the value i want to know how to get **/)
{ return true; }
else
{ return false; }
}
您只需使用index
即可确定。从 here 阅读更多内容。
index. The index of item in the array. (The index value changes if the
array is sorted or filtered)
<span>{{item}}</span><span hidden$="[[computeSpanHidden(taxonomy,index)]]"> > </span>
computeSpanHidden: function(taxonomy,index){
return (taxonomy.length - 1) === index
}
我正在尝试从字符串数组创建面包屑。
我有一个名为 taxonomy
的数组 属性,它看起来像 ["categories", "clothing", "men", "suits"]
。像这样使用 dom-repeat
:
<template is="dom-repeat" items="{{taxonomy}}" id="breadcrumbs">
<span>{{item}}</span><span hidden$="[[computeSpanHidden]]"> > </span>
</template>
生成的视图如下所示:
类别>服装>男装>套装>
我想要删除最后一个 > 得到这样的东西:
类别>服装>男装>套装
我已经尝试通过绑定到我想隐藏的跨度的隐藏属性来做到这一点,但我被卡住了。不完整的 computeSpanHidden
函数如下所示:
computeSpanHidden: function(){
if(this.taxonomy.slice(-1)[0] == /**the value i want to know how to get **/)
{ return true; }
else
{ return false; }
}
您只需使用index
即可确定。从 here 阅读更多内容。
index. The index of item in the array. (The index value changes if the array is sorted or filtered)
<span>{{item}}</span><span hidden$="[[computeSpanHidden(taxonomy,index)]]"> > </span>
computeSpanHidden: function(taxonomy,index){
return (taxonomy.length - 1) === index
}