这是令人惊讶的,但是简单的函数array.IndexOf无效。
$scope.nextProduct = function (pos, item) {
switch (pos) {
case 0: product = $scope.Menu[0].Breakfast
break
case 1: product = $scope.Menu[0].Lunch
break
case 2: product = $scope.Menu[0].BeforTraining
break
case 3: product = $scope.Menu[0].AfterTraining
break
case 4: product = $scope.Menu[0].Dinner
break
default: product = $scope.Menu[0].Breakfast
break
}
var index = product.indexOf(item.Name);
product[index - 1].IsSelect = false;
product[index + 1].IsSelected = true;
}
答案 0 :(得分:2)
通过此表达式,您将在对象数组中搜索字符串。
product.indexOf(item.Name);
相反,你应该运行:
var res = product.filter(function(elem){
return elem.Name == someValue
})
这将返回与您的值匹配的数组