AngularJS中高亮bookingDBID文本问题求助
Hey there! I see exactly why your highlighting isn't working—let's get this sorted out quickly.
The Root Cause
Right now, when you click a log entry, you pass the bookingDBID to your getBookingLog function, but you never update the global $scope.bookingDBID variable that your ng-class condition depends on. Your ng-class="{selected: x.bookingDBID === bookingDBID}" checks against $scope.bookingDBID, which stays stuck as null forever. That's why the red background never triggers!
The Simple Fix
All you need to do is add one line inside your getBookingLog function to update $scope.bookingDBID with the clicked entry's ID. Here's the modified Angular code:
$scope.bookingDBID = null; $scope.getBookingLog = function(bookingDBID){ // Add this line to sync the clicked ID with your scope variable $scope.bookingDBID = bookingDBID; $scope.book = {}; $scope.book.PID = $stateParams.id; $scope.book.bookingDBID = bookingDBID; $scope.showloader=true; var Indata ='data='+angular.toJson($scope.book)+'&method=getBookingLog&service=bookings'; $http({ method: 'POST', url: 'sl/service/middleservice.php', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: Indata }).success(function (response) { $scope.showloader=false; if(response == 'noSession') { location.href = 'login.php'; }else { if(response) { $scope.res = response.reverse(); $scope.cnt = $scope.res.length; } $scope.loadingdiv= false; $scope.$modalInstance1 = $modal.open({ scope: $scope, templateUrl: "bookinglog.html", size: 'lg1', }); } }); }
How This Works
When you click a log entry:
- We immediately set
$scope.bookingDBIDto the clicked entry's ID - The
ng-classcondition now matches the clicked entry'sbookingDBIDagainst the updated scope variable - The
selectedclass (red background) will be applied to the clicked entry right away
Quick Double-Check
Make sure the bookingDBID values in your res array are the same data type (string/number) as the one stored in $scope.bookingDBID. If one's a string and the other's a number, the strict equality (===) won't match. If that happens, you can either use loose equality (==) or convert both to the same type (e.g., parseInt(bookingDBID) if they're numeric IDs).
内容的提问来源于stack exchange,提问作者Paras Prajapati

