小编Hon*_*ake的帖子

仅列出对象数组的一个属性

我想要一个Angular列表,​​显示来自一个对象数组的一个对象属性的所有实例,仅此而已 - 例如,只有国家/地区.

$scope.testSites = [
                { "site": "Testsite1", "country": "Country1", "customer": "Customer1"},
                { "site": "Testsite2", "country": "Country2", "customer": "Customer2"}
            ];
$scope.chosenCategory = 1;
$scope.categoryNames = ["site", "country", "customer"];
$scope.aspect = $scope.categoryNames[$scope.chosenCategory];
Run Code Online (Sandbox Code Playgroud)

但是,我想使用上面的变量'aspect'来选择要在列表中显示的属性.像{{x.country}}之类的东西虽然有效但却不够.我试过这个,但它返回一个空列表:

<table border="1" class="list-group-item list-group-item-success">
            <tr>
                <th>{{aspect | capitalize}}</th> 
            </tr>

            <tr ng-repeat="x in testSites | orderBy:myOrderBy">
                <td>
                    {{x.aspect}}
                </td>

            </tr>
        </table>
Run Code Online (Sandbox Code Playgroud)

有什么我可以做的吗?

javascript angularjs

4
推荐指数
1
解决办法
71
查看次数

标签 统计

angularjs ×1

javascript ×1