AngularJS检索特定名称/对象

时间:2018-10-08 06:44:31

标签: javascript html angularjs

我不确定该如何表达问题,因此,如果发现错误,请原谅我。 我想做的是从数组中检索名称,例如:

enter image description here

数组看起来像这样,我只想单独检索“ NAME”。那可能吗? PS:我想从所有人中检索(例如,我有50个计数,我想检索所有50个名称)

要添加,我将其存储为: 感谢您的任何事先帮助!

            $http({
                    method: 'GET',
                url: 'url'
                    }).then(function successCallback(response) {
                        $scope.exhibitions = response.data.SrchResults;

                    }, function errorCallback(response) {
                        console.log(response);
                    });

2 个答案:

答案 0 :(得分:1)

<div ng-repeat="exhibition in exhibitions">
    <span ng-if="exhibition.NAME">{{ exhibition.NAME }}</span>
</div>

尝试将此代码放在

之后的行
  

$ scope.exhibitions = response.data.SrchResults;

为了显示它们。试试这个

{{1}}

该代码未经测试。随时调整需要的地方。

答案 1 :(得分:1)

ES6的位在这里。

JS

var srchResults = response.data.SrchResults;
var [first, ...exhibitions] = srchResults;
$scope.exhibitionNames = exhibitions.map(item=>item.NAME);

HTML

<div ng-repeat="exhibitionName in exhibitionNames">
    <span ng-if="exhibitionName">{{exhibitionName}}</span>
</div>

希望它会对其他人有所帮助。 :)