gpt4 book ai didi

自动完成所需的 AngularJS 多个范围

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

我有一个这样的数组结构。

[
{
"id": "1",
"name": "John",
"city": "NY"
},
{
"id": "2",
"name": "Gerold",
"city": "LA"
},
{
"id": "3",
"name": "Stuart",
"city": "Boston"
}
]

我需要像下面这样的 $scope 来进行自动完成搜索。

$scope.name=["john","Gerold","Stuart"];
$scope.city=["NY","LA","Boston"];

任何人都可以使用 angularjs Controller 帮助获得它。提前致谢!

最佳答案

使用 map

$scope.users = [
{
"id": "1",
"name": "John",
"city": "NY"
},
{
"id": "2",
"name": "Gerold",
"city": "LA"
},
{
"id": "3",
"name": "Stuart",
"city": "Boston"
}
];

$scope.cities = $scope.users.map(function(obj){

return obj.city;
});

console.log($scope.cities);

关于自动完成所需的 AngularJS 多个范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41016988/

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