gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:32:13 25 4
gpt4 key购买 nike

我在这里创建了一个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

关于javascript - AngularJS - For 循环推送整个对象而不仅仅是标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26689125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com