AngularJS:重复多个阵列时prevent显示上次分离器 [英] AngularJS: Prevent displaying the last separator when repeating multiple arrays
问题描述
问:什么是从未显示最优雅的方式,以确保每行的最后一个分隔符
Question: What is the most elegant way to ensure the last separator on each line is never shown?
11|18|3|8|12|1|22|31|61|
11:18:3:8:12:1:22:31:
11,18,3,8,12,61,
1 22 31
请注意,该数据从三个不同的阵列,例如,用于1行的数据被定义为来源于:
Note that the data originates from three different arrays, e.g., the data for line 1 is defined as:
$scope.numbers = [11,18,3,8,12];
$scope.specialNumbers = [1,22,31];
$scope.additionalNumbers = [61];
我希望看到一个更优雅/角度的方式,不只是找到最后一个<李>
,并使用 $元素中删除分隔符。找到
,或类似的。
我创建了一个小的jsfiddle 的例子来说明这个问题。
I created a little JSFiddle example to demonstrate the problem.
感谢
推荐答案
下面是一个完整的解决方案,利用所提出的 $最后
检查(仅一次)结合 Array.concat
,这是在角前pressions支持,因此支持绑定。然而,要正确重复的文字,你需要另外通过跟踪指数$
。
Here is a complete solution, using the proposed $last
check (only once) in combination with Array.concat
, which is supported in Angular expressions and thus supports bindings. However, to correctly repeat literals, you need to moreover track by $index
.
"<li ng-repeat='num in numbers.concat(specialNumbers,additionalNumbers) " +
"track by $index'>" +
"<span>{{ num }}</span><span ng-if='!$last'>{{ separator }}</span>" +
"</li>"
这篇关于AngularJS:重复多个阵列时prevent显示上次分离器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!