我有一个teamDetails
数组,其中是一个squad
数组,其中是player
对象。每个玩家对象都有一个injured
包含值"true"
or的属性"false"
。
我想编写一个循环遍历数组的函数,只返回受伤属性评估为真的玩家。
这是我到目前为止(不工作):
$scope.injuredPlayerSearch = function() {
var injuredPlayers = [];
$scope.teamDetails.squad.forEach(function(o) {
if (o[injured] === true) {
injuredPlayers.push(o)
}
});
return injuredPlayers;
}
我看不出这有什么问题。如果有人可以,将不胜感激。