从 ng-options in select drop downusing filter 拼接

Splice from ng-options in select drop downusing filter

如何拼接数组中的一些元素以在 ng 选项中显示它

这是JSON

    $scope.result=[
            {
                "id": 1,
                "name": "min",

            },
            {
                "id": 2,
                "name": "hour",

            },
            {
                "id": 3,
                "name": "second",

            },
            {
                "id": 4,
                "name": "inch",

            },
            {
                "id": 5,
                "name": "km",

            }
    ]

我想从数组中拼接inch和km显示出来select dropdown

<select ng-options="r.id as r.name for r in result"><option value="">--Select---</option></select>

还尝试过仅根据 id 显示的内嵌过滤器,例如 tihis <select ng-options="r.id as r.name for r in result|filter:{id:'!4'}"><option value="">--Select---</option> </select>

但这只会拼接一个元素,即id:5(km)。我也想拼接id:4

为您的作品使用原生 javascript filter

var newResult = $scope.result.filter(function(obj){
  return obj.name === 'km' || obj.name === 'inch';
});
console.log(newResult); // will give expected result.

您可以将过滤器的结果分配给要循环的 scope 中的键。