Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Angularjs 对表中的行使用ng repeat和ng类_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Angularjs 对表中的行使用ng repeat和ng类

Angularjs 对表中的行使用ng repeat和ng类,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我使用的是AngularJS,我想要得到的效果与它产生的效果类似,假设它能工作(但它不能) 看法 我意识到这段代码不起作用,因为person对ng class不可用,因为它只对每行中的对象可用。代码是为了了解我要做的事情:即,我希望能够使用ng repeat创建表行,其类也基于一个条件,该条件取决于对行本身的作用域特性的访问,例如person。我意识到我可以在专栏中添加ng类,但那很无聊。有谁有更好的想法吗?实际上,你可以在你所指的上下文中使用“person”。它存在于正在重复的项以及其中的任何

我使用的是AngularJS,我想要得到的效果与它产生的效果类似,假设它能工作(但它不能)

看法


我意识到这段代码不起作用,因为
person
ng class
不可用,因为它只对每行中的对象可用。代码是为了了解我要做的事情:即,我希望能够使用
ng repeat
创建表行,其类也基于一个条件,该条件取决于对行本身的作用域特性的访问,例如
person
。我意识到我可以在专栏中添加ng类,但那很无聊。有谁有更好的想法吗?

实际上,你可以在你所指的上下文中使用“person”。它存在于正在重复的项以及其中的任何项上。原因是特定元素上的任何指令都共享相同的$scope对象。ng repeat的优先级为1000,因此它已经创建了$scope并将“person”放入其中,因此“person”可用于ng类

参见本Plnkr:


这实际上应该可以正常工作。Person应该在tr元素及其子元素上可用,因为它们共享相同的范围

这对我来说似乎很好:

<table>
    <tr ng-repeat="person in people" ng-class="rowClass(person)">
        <td>{{ person.name }}</td>
    </tr>
</table>

{{person.name}

通常我想给出一个更全面的答案,但这一部分涉及的代码太多,无法做到这一点。因此,我将展示什么是最重要的,并希望看到这一点的任何人都知道如何使用它。我的动态JSON数组中既有列也有行,但这一点最重要的是ng show=“$last”。这应该只显示动态JSON数组中的最后一行

<tr ng-repeat="row in table.rows" ng-show="$last">

   <td ng-repeat="column in table.cols" ng-show="column.visible == true" nowrap >{{row[column.columnname]}}</td>
</tr>

{{row[column.columnname]}
<table>
    <tr ng-repeat="person in people" ng-class="rowClass(person)">
        <td>{{ person.name }}</td>
    </tr>
</table>
<tr ng-repeat="row in table.rows" ng-show="$last">

   <td ng-repeat="column in table.cols" ng-show="column.visible == true" nowrap >{{row[column.columnname]}}</td>
</tr>