Need help updating a boolean property for all objects in an array with the same user ID. I've outlined my MVC framework below in a concise manner.
Model:
var posts = [{id:1, user_id:1, is_following:true},
{id:2, user_id:1, is_cool:true},
{id:2, user_id:2, is_cool:false}];
View:
<div class="list" ng-repeat="post in posts">
<button ng-click="unCool(post.user_id,$index)" ng-if="post.is_cool === true">
Cool
</button>
<button ng-click="makeCool(post.user_id,$index)" ng-if="post.is_cool === false" >
not Cool
</button>
<p>{{post.id}}</p>
</div>
Controller:
$scope.makeCool =function(userid, index){
//this is an ajax request for brevity i excluded the service
coolService.makeCool(user_id)
.success(function (data) {
$scope.posts[index].is_following = true;
//How to locate and update other indexes with the same user ID
}).
error(function(error, status) {
//do something
});
}
$scope.unCool =function(userid, index){
//this is an ajax request for brevity i excluded the service
coolService.unCool(user_id)
.success(function (data) {
$scope.posts[index].is_following = false;
//How to find and toggle other indexes with the same user ID
}).
error(function(error, status) {
//do something
});
}