I have two sets of arrays, $scope.Skills and $scope.skillslist.
The Skills array has a ton of values, so I'm only including the ones relevant to the question:
$scope.Skills = [
{LotsOfValues: "blah", Skill_Values__c: "1"},
{LotsOfValues: "blah", Skill_Values__c: "2"},
{LotsOfValues: "blah", Skill_Values__c: "3"}
];
And the skillslist array:
$scope.skillslist = [
{Skill_Values__c: "1", Checked: ""},
{Skill_Values__c: "2", Checked: ""},
{Skill_Values__c: "3", Checked: ""},
{Skill_Values__c: "4", Checked: ""},
{Skill_Values__c: "5", Checked: ""},
{Skill_Values__c: "6", Checked: ""},
{Skill_Values__c: "7", Checked: ""}
];
What I want to do is, for each item in the skillslist, run it against the items in Skills, and if there's a match, set Checked to true, if not set it to false. How can this be accomplished?
I'm using the forEach function and this is what I have so far:
angular.forEach(skills, function (value) {
console.log("FOR EACH");
for (var i = 0; i <= $scope.skillslist.length; i++) {
if ($scope.skillslist[i].Skill_Values__c === value.Skill_Values__c) {
$scope.skillslist[i].Checked = "Added";
} else {
$scope.skillslist[i].Checked = "no";
}
}
});
But straight away I know I'm doing it wrong because I should be looking forEach skillslist right? But when I do that I have no idea how to then change the Checked value for each one. Swapping all Skills for skillslist didn't help.
In my ng-repeat of skillslist, I see the first item has a Checked value of "Added", the rest have a Checked value of "no".
I've been reading through forEach examples, but couldn't find any related to what I'm trying to do, about referencing two different arrays in this way. Any pointers would be appreciated!