Ng-repeat从下一个索引开始,而不是始终从零开始

时间:2015-10-30 05:15:37

标签: angularjs

我有这个HTML

<div class="list card" ng-repeat="comment in allComments">
       <content>
</div>

$scope.allComments.push(d.data[i]);

问题是每次向allComments ng-repeat添加一个新元素时从0开始循环。每当新条目被推送到数组时,我如何继续将元素附加到div而不是每次从0循环。

我要说第一次在allComments中推送5条记录,然后ng-repeat将从allComments[0]开始到allComments[4]并显示5 content。所以它会是这样的:

<div class="list card">
       <content ..0>
       <content ..1>
       <content ..2>
       <content ..3>
       <content ..4>
</div>

下次再次推送allComments中的5条记录,然后ng-repeat将从allComments[0]开始到allComments[9],并清除content内的所有div并将重新渲染10 content

<div class="list card">
       <content ..0>
       <content ..1>
       <content ..2>
       <content ..3>
       <content ..4>
       <content ..5>
       <content ..6>
       <content ..7>
       <content ..8>
       <content ..9>
</div>

所以我想要的是这次它应该从allComments[5]开始到allComments[9]并继续追加<content>而不是完全呈现div内的内容

2 个答案:

答案 0 :(得分:1)

您可以查看我的plnkr以获取更多信息

    public static PrintStream getOutputPrintStream(Scanner console) {
        boolean done = false;
        PrintStream output = null;
        while (!done) {
            System.out.print("Enter output file: ");
            File outFile = new File(console.next());

            if (outFile.exists()) {
            // if file exixts
                  System.out.print("The file " + outFile + " already exists, would you like to overwrite it? (y/n): ");
                  char decision = console.next().toLowerCase().charAt(0);
                  if (decision == 'y') {
                     done = true;
                      output = createStream(outFile);
                   }
             } else {
            // if file does not exist
                done = true;
                output = createStream(outFile);
            }
        }
        return output;
    }

static PrintStream createStream(File outFile) {
    PrintStream output = null;
    try {
        output = new PrintStream(outFile);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return output;
}

答案 1 :(得分:1)

如果您的allComments对象上有id属性,那么您可以使用ng-repeat track by来完成此操作。

您的HTML应如下所示:

DECLARE @column_date VARCHAR(50)
SET @column_date = '18/1/2012 18:51:35'

SELECT DATEDIFF(DAY,CAST(CONVERT(DATETIME,@column_date,103) AS DATETIME),GETDATE())