Html引导程序表未显示在屏幕上

Html bootstrap table not appearing on screen

本文关键字:屏幕 显示 程序表 Html      更新时间:2024-04-08

我在html中显示表格时遇到问题。当我硬编码表中的值时,它们会出现,但当使用angularjs时,它们不会出现。所以我认为这个问题与语言有关。这是我试图显示的html代码:

 <div class="container">
 <h2>Hover Rows</h2>
 <p>The .table-hover class enables a hover state on table rows:</p>            
 <table class="table table-hover">
 <thead>
  <tr>
    <th>Friends</th>
  </tr>
 </thead>
 <tbody>
    <tr ng-repeat="Friends in AllUsersFriends">
        <td>{{Friends}}</td>
  </tr>
 </tbody>
 </table>
 </div>

这是我的controller.js代码:

    socket.on("AllFriends",function (Friends){
  $log.log('so the friends are');
  $scope.AllUsersFriends=Friends;
  console.log($scope.AllUsersFriends);
  $scope.$apply();
});

我通过flask socketio收到一个数组,然后我将该数组设置为我创建的$scope.AllUsersFriends数组。我在控制台中看到了数据,但屏幕上没有显示任何行。如何使我的数据显示在屏幕上?谢谢

所以我解决了我的问题,问题是数组中的数据实际上正在更新,但我的应用程序中有不同的页面,一旦我更改页面,数据就会丢失,然后我通过在服务中创建相同的数组来解决这个问题,这样更改是全局的,数据不会从数组中擦除。所以表格总是显示出来,只是没有任何数据可以显示。感谢

看看这个:

<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
 <table class="table table-hover">
    <tr><th>Friends</th></tr>
    <tr ng-repeat="x in friends"><td>{{x.name}}</td></tr>
 </table>
<script>
//App declaration
var app = angular.module('myApp',[]);
//Controller Declaration
app.controller('myCtrl',function($scope){
    $scope.friends = [{name: "Peter"},{name:"Laila"},{name:"Rosy"}];
});
</script>
</body> 
</html> 

希望,它解决了!