我正在从数组中填充一个下拉按钮。正如您在图片中看到的那样显示整个键值对。
1)我只需要显示Label的值。
2)我想拥有"所有地点"作为默认项目。
以下是地点的样子:
Locations:Array[2]
0:Object
$$hashKey:"object:772"
Id:1600
Label:"California"
__proto__:Object
1:Object
$$hashKey:"object:773"
Id:1600
Label:"Atlanta"
__proto__:Object
HTML:
<div class="btn-group btn-toolbar btn-margin-left" style="float: right;">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
ALL LOCATIONS {{selectedItem}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li ng-repeat="Label in Summary.Locations">
<a ng-click="dropboxitemselected(Label)">
{{Label}}</a>
</li>
</ul>
</div>
js:
WotcDashBoardModuleService.GetDashBoardSummary(Ein).then(function (response) {
$scope.Summary = response.data.WotcSummary;
$scope.selectedItem;
$scope.dropboxitemselected = function (item) {
$scope.selectedItem = item;
//alert($scope.selectedItem);
}
console.log($scope.Summary);
});
答案 0 :(得分:1)
Summary.Locations是您的对象数组,因此Label
会单独绑定到每个元素。这意味着您需要显示{{Label.Label}}
而不仅仅是{{Label}}
,并且您会看到名称。
答案 1 :(得分:1)
这部分:
ALL LOCATIONS {{selectedItem}}
应替换为:
<span ng-if="!selectedItem">ALL LOCATIONS</span>
<span ng-if="selectedItem" ng-bind="selectedItem.Label"></span>
或者用:
<span>{{ selectedItem ? selectedItem.Label : 'ALL LOCATIONS' }}</span>