显示只开放格与角度,如果 [英] Show only open div with angular if

查看:146
本文介绍了显示只开放格与角度,如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想acheive相同的行为如下春天code:

I'm trying to acheive the same behavior as the spring code below:

<c:forEach items="${data}" var="data" varStatus="contador">
    <c:if test="${(contador.count-1)%3==0}">
        <div class="conjunto-${conjunto} row"> <!-- Show opening div -->
    </c:if>

        <!-- Some HTML goes here -->

     <c:if test="${((contador.count-1)%3==2)}">
         </div>
    </c:if>
</c:forEach>

解释:我想从类一个新的div 已添加3其他HTML元素之后。

Explaining: I want a new div from class row only after 3 other HTML elements have been added. I have tried this with ng-if, like this:

<div ng-repeat="data in DATA">
    <div class="conjunto-{{$index/3}} row" ng-show="$index % 3 == 0" ng-include="'html.html'">
    </div>

    <div ng-show="$index % 3 != 0" ng-include="'html.html'">
    </div>
</div>

但它显然行不通,因为只有一个元素用在里面去div.row。

But it obviously doesnt work because only one element with be inside de div.row.

是否有一个if子句与我可以添加开场仅股利再后来关闭它?

Is there an if-clause with which I could add only the opening div and then close it later?

先谢谢了。

推荐答案

确定这样做IMO最好的办法就是2倍,在你的控制器有一个类似的方法

Ok the best way to do this IMO is 2 fold, in your controller have a method similar to this

$scope.createDataChunks = function() {
    var a = $scope.DATA,
        retArr = [];
    while(a.length) {
       retArr.push(a.splice(0,3));
    }

    return retArr;
}

这会给你一个数组的数组,它每片含3(或更少)的项目,那么你有这个作为你的标记

This would give you an array of arrays, each containing 3 (or less) items in it, you then have this as your markup

<div ng-repeat="data in createDataChunks()">
    <div class="conjunto-{{$index/3}} row" ng-show="$index % 3 == 0" ng-include="'html.html'">
        <!-- put custom HTML here -->
    </div>
</div>

我想这是大概你所追求的?

I think that's roughly what you are after?

这篇关于显示只开放格与角度,如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆