Javascript 使用Angularjs显示多个相同的JSON键
当我键入Monday并单击Search时,我希望获得所有Monday的JSON数据,而不仅仅是第一行。我尝试过修改forEach函数,并在html中使用了两个ng repeat。我猜是JSON数据结构? .Javascript 使用Angularjs显示多个相同的JSON键,javascript,json,angularjs,angularjs-ng-repeat,Javascript,Json,Angularjs,Angularjs Ng Repeat,当我键入Monday并单击Search时,我希望获得所有Monday的JSON数据,而不仅仅是第一行。我尝试过修改forEach函数,并在html中使用了两个ng repeat。我猜是JSON数据结构? . 您需要使用以下代码: angular.forEach($scope.items, function (value, key) { if (key === enteredValue) { angular.forEach(value,
您需要使用以下代码:
angular.forEach($scope.items, function (value, key) {
if (key === enteredValue) {
angular.forEach(value, function(item) {
$scope.results.push({
name: key,
address: item.Address,
phone: item.Phone,
status: item.Status
});
});
}
});
问题是你只使用了一个forEach,而实际上你需要两个forEach。您的数据结构没有问题
但是,您也可以这样做:
angular.forEach($scope.items[enteredValue], function (item, key) {
$scope.results.push({
name: enteredValue,
address: item.Address,
phone: item.Phone,
status: item.Status
});
});
这就更简单了。我希望这有帮助 谢谢。
angular.forEach($scope.items[enteredValue], function (item, key) {
$scope.results.push({
name: enteredValue,
address: item.Address,
phone: item.Phone,
status: item.Status
});
});