对于存储在数组中的每个数据,在单独的 <td> 中呈现 ng-repeat 值。 AngularJS
Present ng-repeat values in separate <td> for each data stored in array. AngularJS
使用 ng-repeat 时,从后端发送的数组值必须分开并出现在不同的行中。我有一个从数据库获取数据的数组,但是它将所有数据保存在第一个索引中。
后端
List <String> sportsValues;
Angular JS
$scope.sports = { values: [] };
if (scope.sports.values.length > 0) {
$scope.sports.values.push(sportsValues)
};
HTML
<table>
<tr ng-repeat="value in sports.values">
<td> {{ values }} </td>
</tr>
</table>
当前结果
[["football, basketball, baseball"]]
如果我这样做,$scope.sports.value(0) = {"football, basketball, baseball"}
table
中的预期结果
football
basketball
baseball
人们建议在 CSS 中加入、列出分隔符并拆分,但其中 none 行得通。
一个简单的指南或提示将不胜感激。
如果你只想打印第一个实例,那么
<table>
<tr ng-repeat="value in sports.values[0]">
<td> {{ value }} </td>
</tr>
</table>
更新
您想打印每个 tr
中的所有值,然后只需更改为 $scope.sports.values
赋值的方式
$scope.sports = { values: [] };
if(angular.isArray(sportsValues)) {
$scope.sports.values = sportsValues[0].split(",");
}
然后将 ng-repeat
更改为您之前的
<table>
<tr ng-repeat="value in sports.values">
<td> {{ value }} </td>
</tr>
</table>
使用 ng-repeat 时,从后端发送的数组值必须分开并出现在不同的行中。我有一个从数据库获取数据的数组,但是它将所有数据保存在第一个索引中。
后端
List <String> sportsValues;
Angular JS
$scope.sports = { values: [] };
if (scope.sports.values.length > 0) {
$scope.sports.values.push(sportsValues)
};
HTML
<table>
<tr ng-repeat="value in sports.values">
<td> {{ values }} </td>
</tr>
</table>
当前结果
[["football, basketball, baseball"]]
如果我这样做,$scope.sports.value(0) = {"football, basketball, baseball"}
table
中的预期结果football
basketball
baseball
人们建议在 CSS 中加入、列出分隔符并拆分,但其中 none 行得通。 一个简单的指南或提示将不胜感激。
如果你只想打印第一个实例,那么
<table>
<tr ng-repeat="value in sports.values[0]">
<td> {{ value }} </td>
</tr>
</table>
更新
您想打印每个 tr
中的所有值,然后只需更改为 $scope.sports.values
$scope.sports = { values: [] };
if(angular.isArray(sportsValues)) {
$scope.sports.values = sportsValues[0].split(",");
}
然后将 ng-repeat
更改为您之前的
<table>
<tr ng-repeat="value in sports.values">
<td> {{ value }} </td>
</tr>
</table>