AngularJS-循环推送整个对象,而不仅仅是标题

AngularJS - For loop to push whole object than just title

本文关键字:不仅仅是 标题 对象 循环 AngularJS-      更新时间:2023-09-26

我在这里创建了一个plunkr:http://plnkr.co/edit/wPCex3lJc5E0I4fSeXI1?p=preview

应用程序应该允许用户执行搜索并返回结果。

我已经到了显示正确结果数量的地步(如果只选择了一个国家),但我似乎无法在for循环中通过整个匹配对象。

HTML:

<div ng-repeat="myresults in Results track by $index">
    {{myresults}}
</div>

JS:

$scope.Results = [];  
$scope.search = function(country, city, department) {
    var countryValue = country.Country;
    for (i = 0; i < $scope.Data.length; i++) {
      if ($scope.Data[i].Country == countryValue) {
        $scope.Results.push(countryValue);
      }
    }
    console.log($scope.Results);
  }

您只是在$scope.Results中推送国家名称,而不是推送整个数据对象:

$scope.Results.push($scope.Data[i]);

http://plnkr.co/edit/DH8DBUKoWKITIyaEH1yD?p=preview