大家好,我正在尝试用angulajs绑定一个表。我正在从表中的数据库中获取数据,并尝试填充该表。在这里我做到了
$scope.getPageDetails = function () {
$http.get('/api/privilege/getpagedetails/')
.success(function (data, status) {
$scope.Page = data;
console.log($scope.Page);
}).error(function () {
});
}然后,我以定义为$scope.Page = [];的$scope.Page格式获取数据。在这里,我附加了以$scope.page格式获取数据的控制台图像

这是我的桌子
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>
ID
</th>
<th>
PageName
</th>
<th>
PageUrl
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Page in Pages">
<td>{{Page.id}}</td>
<td>{{Page.pageName}}</td>
<td>{{Page.pageUrl}}</td>
<td>
<input type="checkbox" value="Edit" />
</td>
</tr>
</tbody>
</table>请帮助我缺少的地方,我将非常感谢你们所有人。
发布于 2016-12-07 22:44:38
在您的视图中,您正在迭代Pages,但我没有在您的控制器中看到它的定义。
改变
$scope.Page = data;至
$scope.Pages = [data];最终代码HTML:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>
ID
</th>
<th>
PageName
</th>
<th>
PageUrl
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="Page in Pages">
<td>{{Page.id}}</td>
<td>{{Page.pageName}}</td>
<td>{{Page.pageUrl}}</td>
<td>
<input type="checkbox" value="Edit" />
</td>
</tr>
</tbody>
</table>控制器:
$scope.getPageDetails = function () {
$http.get('/api/privilege/getpagedetails/')
.success(function (data, status) {
$scope.Pages = [data];
}).error(function () {
});}
编辑:如果你的数据是一个对象,那就把它变成一个数组,这样ng-repeat就可以遍历它了
发布于 2016-12-07 22:55:56
$scope.getPageDetails = function () {
$http.get('/api/privilege/getpagedetails/')
.success(function (data, status) {
$scope.Pages = data; //change page to pages in whole code,
//no need to change any thing in html page
console.log($scope.Pages);
}).error(function () {
});
}发布于 2016-12-07 22:43:25
控制器中的$scope.Page与HTML repeat绑定中的Pages,您需要编写$scope.Pages :)
https://stackoverflow.com/questions/41020295
复制相似问题