<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>User Management- M&M</title>
<link rel="icon" href="images/logo.jpg">
<link href="css/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/userApp.js"></script>
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">-->
<!--<link href="CSS/Home.css" rel="stylesheet" />-->
</head>
<body ng-app="myApp" ng-controller="myController">
<nav class="navbar navbar-expand-lg navbar-light" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="index.html">
<img src="images/logo.jpg" alt="M&M" width="110" />
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="LoginPage.html">Login</a>
</li>
<li class="nav-item">
<a class="nav-link active js-scroll-trigger" href="User_Mgmt.html">User Management</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="CompanyManagement.html">Company Management</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="ProductPage.html">Product Management</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="ShoppingCart_Group5_Team1.html">Shopping Cart</a>
</li>
</ul>
</div>
</div>
</nav>
<header class="subhead">
<div class="container">
<div class="row">
<div class="col-xs-6 col-md-6">
<input class="form-control" id="ex3" type="text" placeholder="Search Users" ng-model="searchUsers">
</div>
<div class="col-xs-6 col-md-6">
<button type="button" class="btn btn-info btn-lg float-right" data-toggle="modal" data-target="#myModal">Add New</button>
</div>
<div class="clearfix"></div>
</div>
<hr>
<table class="table table-striped table-hover">
<thead>
<tr class="table100-head">
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>Contact</th>
<th>Role</th>
<th>Company</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in selectedUsers | filter: searchUsers track by $index">
<td>{{user.email}}</td>
<td>{{user.firstName}}</td>
<td>{{user.lastName}}</td>
<td>{{user.contact}}</td>
<td>{{user.role}}</td>
<td>{{user.company}}</td>
<td>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModalEdit" ng-click="selectUser(user)">Edit</button>
</td>
<td>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModalDelete" ng-click="selectUser(user)">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</header>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
我正在尝试创建一个网页,当用户登录时,根据登录用户的公司,我需要显示“用户”数组中的用户选择列表。
问题出在push()方法之后,控制台日志和调试都将数据显示在selectedUsers列表中,而不是在浏览器中显示。
例如-当属于Apple公司的用户登录时,在此表中,仅应显示属于APPLE公司的用户。
作为参考-“ currentUser”是使用localStorage.getItem()从登录页面获取的数组。
“用户”数组包括来自各个公司的所有用户的列表。
“ selectedUsers”一个空数组,其中仅显示属于一个公司的用户。通过使用currentUser数组对用户数组使用for循环来完成此操作。之后,我将过滤后的用户数据推送到selectedUsers数组中,并将其显示在表格中。
我听说过称为异步的功能。我应该用那个吗?我不知道在哪里以及如何实现。
正在寻找指导。预先感谢。
PS:是的,我在HTML页面的selectedUsers中使用了ng-repeat用户来显示selectedUsers。
//Info-
//currentUser- user array acquired from the login user page.
// Users- List of all static users in the array.
// selectedUsers- List of users displayed and filtered from the users array based on currentUser.company
if (localStorage.getItem("currentUser") !== null) {
var currentUser = JSON.parse(localStorage.getItem("currentUser"));
console.log("Received", currentUser);
}
else {
console.log("Not received");
}
if (localStorage.getItem("users") === null) {
$scope.users = [
{ email: "John@yahoo.com", password: "John123", firstName: "John", lastName: "Doe", contact: "281-283-2480", role: "Supplier-Admin", company: "Apple" },
{ email: "Rick@yahoo.com", password: "Rick123", firstName: "Rick", lastName: "Fraiser", contact: "987-283-2489", role: "Supplier-User", company: "Apple" },
{ email: "Sam@yahoo.com", password: "Sam123", firstName: "Sam", lastName: "Tarly", contact: "456-786-2480", role: "BuyerAdmin", company: "Samsung" }
];
localStorage.setItem("users", JSON.stringify($scope.users));
} else {
$scope.users = JSON.parse(localStorage.getItem("users"));
}
//filter users based on currentUser's role and push into selectedUsers
for (var i = 0; i<$scope.users.length; i++) {
$scope.selectedUsers = [{}];
if ($scope.users[i].company === currentUser[0].company) {
$scope.selectedUsers.push($scope.users[i]);
}
console.log("filteredUsers", $scope.selectedUsers);
localStorage.setItem("selectedUsers", JSON.stringify($scope.selectedUsers));
}