Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何计算ng if中的事务并放入`<;div>;`只有当条件为真时?_Javascript_Jquery_Html_Css_Angularjs - Fatal编程技术网

Javascript 如何计算ng if中的事务并放入`<;div>;`只有当条件为真时?

Javascript 如何计算ng if中的事务并放入`<;div>;`只有当条件为真时?,javascript,jquery,html,css,angularjs,Javascript,Jquery,Html,Css,Angularjs,我只想在$scope.grp中的x除以3时不留余数的情况下添加一行。我正在尝试以下代码 <div class="card"> <div ng-repeat="x in grp"> <div class="row"> <div ng-if="x%3==0"> <div class="row"> </div> <div class="col co

我只想在
$scope.grp
中的
x
除以3时不留余数的情况下添加一行。我正在尝试以下代码

 <div class="card">
  <div ng-repeat="x in grp">
     <div class="row">
        <div ng-if="x%3==0">
           <div class="row">
        </div>
    <div class="col col-33">
       /my rest of code here/
     </div>
     </div>
   </div>
<div>

/我剩下的代码在这里/
有什么建议吗?

检查以下内容: 如果提醒为0,则将添加行

<div class="card">
<div ng-repeat="x in grp">
  <div class="row">
    <div ng-if="x%3==0">
      <div class="row">
        reminder 0
      </div>
    </div>
    <div class="col col-33">
      my rest of code here
    </div>
  </div>
</div>

代码笔:

不确定以下内容是否正确。但实现这一目标的方法如下

<div data-ng-app="" data-ng-init="grp=['one','two','three','four','five','six','seven']" class="container">
  <div ng-repeat="x in grp" ng-if="$index % 3 == 0" class="row">
     <div class="col-xs-3">{{grp[$index]}}</div>
     <div class="col-xs-3" ng-if="$index + 1 < grp.length">{{grp[$index+1]}}</div>
     <div class="col-xs-3" ng-if="$index + 2 < grp.length">{{grp[$index+2]}}</div>
   </div>
<div>

{{grp[$index]}
{{grp[$index+1]}
{{grp[$index+2]}
我假设
grp
是一个字符串数组,并使用
$index
进行分组


我对angularjs不是很熟悉-但是在这种情况下,您的html结构是错误的。您的结构将在每三个div之前创建一个空的“row”列。我不知道是否有办法在ng if中打开一个“div”标记,然后在以后关闭它

<>你应该考虑只为你的卡创建数组块。因此,每个区块将容纳3张卡,然后您可以循环第一级区块,然后循环第二级阵列。它看起来是这样的:

<div class="card">
    <div ng-repeat="grp in chunks">
        <div class="row">
            <div ng-repeat"x in grp"> // as mentioned, I got no clue about angularjs, so I don't know how to correctly address the values within the groups
                <div class="col col-33">
                    my rest of code here
                </div>
            </div>
        </div>
    </div>
</div>

你能展示grp的内容吗?你能分享你的angularJs代码吗?或者你只需要建议?如果
grp
只是一个numbers@zan
app.controller(“createMessageController”,函数($scope,$http,$cookies){var userId=$cookies.get('userId');var password=$cookies.get('password');$http.get('http://www.mysite.in/userGroups/1/100?userId=“+userId+”&password=“+password).then(function(response){$scope.grp=response.data.msg;},function(){location.assign(“error.html”);})
使用$index解决了我现在尝试后面部分时遇到的问题。希望它能工作。非常感谢。:)
<div class="card">
    <div ng-repeat="grp in chunks">
        <div class="row">
            <div ng-repeat"x in grp"> // as mentioned, I got no clue about angularjs, so I don't know how to correctly address the values within the groups
                <div class="col col-33">
                    my rest of code here
                </div>
            </div>
        </div>
    </div>
</div>
var chunks=[[1,2,3],[4,5,6],[7,8,9]];