I've got an array of objects
// Extracted from the database
$scope.users = [{"$id":"1","UserID":3,"Name":"A","Selected":false},{"$id":"2","UserID":4,"Name":"B","Selected":false},{"$id":"3","UserID":5,"Name":"C","Selected":false},{"$id":"4","UserID":6,"Name":"D","Selected":false}]
Next, there's another array containing the users selected from a previous screen
$scope.usersSelected = [{"$id":"3","UserID":5,"Name":"C","Selected":true,"$$hashKey":"object:83"},{"$id":"4","UserID":6,"Name":"D","Selected":true,"$$hashKey":"object:84"}]
The goal is to update the Selected
property in $scope.users
if they are present in $scope.usersSelected
. The approach involves looping through $scope.usersSelected
and checking for corresponding UserID
matches within $scope.users
for (var i = 0; i < $scope.usersSelected.length; i++) {
var obj = $.grep($scope.users, function (e) { return e.UserID == $scope.usersSelected[i].UserID; });
obj.Selected = true;
}
Despite the code logic, the Selected
properties remain unchanged. What could be causing this issue?
Lastly, clarification is needed regarding the data structure in the arrays. Why does the "$id"
appear when fetching from the database, and what is the purpose of "$$hashKey"
when transitioning between screens? Where do these values originate from?
Additional info: Utilizing AngularJS with ASP.NET Web API 2 for database interaction.