2

我有以下代码:

<td>
    <span data-ng-repeat="question in row.questions">{{ question.questionId }},</span>
</td>

这会遍历 row.questions 并给出如下所示的输出:

1,2,3,

我的问题是最后一个逗号。有什么办法可以防止最后一个逗号出现。请注意,我目前使用的是 1.15,但如果 1.2rc 中有一些新的东西会有所帮助,我可以使用它。

这是我目前使用建议的解决方案的 HTML:

    <tr data-ng-show="grid.data.length > 0" data-ng-repeat="row in grid.data | orderBy:problemSortField.key:inverse">
      <td>{{ row.problemId }}</td>
      <td>
         <span data-ng-repeat="question in row.questions">
            {{ question.questionId }}<span data-ng-if="$last">,</span>
         </span> 
      </td>
   </tr>
4

1 回答 1

12

使用$last

<td>
    <span data-ng-repeat="question in row.questions">
        {{ question.questionId }}<span ng-if="!$last">,</span>
    </span>     
</td>           

注意: ngIf是 v1.1.5 中添加的新指令。

于 2013-08-16T14:57:31.447 回答