在Angular.js中使用.json加载表,可以通过以下步骤完成:
[
{
"id": 1,
"name": "John",
"age": 25
},
{
"id": 2,
"name": "Jane",
"age": 30
},
{
"id": 3,
"name": "Bob",
"age": 35
}
]
var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
// 加载JSON文件
$http.get('data.json').then(function(response) {
$scope.tableData = response.data;
});
});
<div ng-app="myApp" ng-controller="myController">
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr ng-repeat="item in tableData">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.age }}</td>
</tr>
</table>
</div>
以上代码将加载data.json文件中的数据,并在表格中显示出来。
在这个例子中,Angular.js使用了$http服务来进行HTTP请求,加载了data.json文件,并将返回的数据赋值给$scope.tableData变量。然后,使用ng-repeat指令遍历$scope.tableData中的每个对象,并在表格中显示出来。
推荐的腾讯云相关产品:腾讯云对象存储(COS),它是一种高可用、高可靠、低成本的云端存储服务,适用于存储和处理大规模非结构化数据。您可以通过以下链接了解更多关于腾讯云对象存储的信息:腾讯云对象存储(COS)。
领取专属 10元无门槛券
手把手带您无忧上云