【发布时间】:2016-09-28 02:53:13
【问题描述】:
我的 app.js 文件中有一个数组,我想在我的 HTML 表中的<td> 行中按顺序打印其内容。
下面是我的 app.js 文件:
(function () {
var app = angular.module('TravelI', []);
var route = [{
source : [
"San Jose",
"San Francisco",
],
destination : [
"Wellington",
"Mumbai"
],
}];
app.controller('RouteController', function ($scope) {
$scope.product = route;
$scope.addRoute = function(s, d) {
};
});
})();
HTML 代码:
<div id="DisplayTable" ng-repeat="x in product">
<table style="width: 80%" align="center">
<tr>
<th>
From
</th>
<th>
To
</th>
</tr>
<tr>
<td>{{x.source[$index]}}</td>
<td>{{x.destination[$index]}}</td>
</tr>
</table>
</div>
现在我只能正确查看数组中第一个元素的数据。我希望显示是这样的:
From To:
San Jose Wellington
San Francisco Mumbai
我附加到两个数组的任何城市都应该在表格行中按顺序显示。
【问题讨论】:
-
它只打印一行,因为您的 product.length 为 1。您必须遍历 product.source。
标签: javascript angularjs arrays angularjs-directive angularjs-scope