angularjs根据另一个选择框选择框值

时间:2016-12-21 22:12:47

标签: angularjs drop-down-menu

我的数据结构是

$scope.selectedNotification = {};

$scope.metricTypes = [{"metric":"storage","units":["%","MB","GB","TB","PB"]},{"metric":"memory","units":["PB","EB","YB"]},{"metric":"vcores","units":["vcores"]}];

我的HTML

<select ng-model="selectedNotification.metricType" ng-options="metricType.metric as metricType.metric for metricType in metricTypes"></select>

<select ng-model="selectedNotification.unit" ng-options="unit for unit in (select as metricType.units for metricType in ( metricTypes | filter: {metric: selectedNotification.metricType }))"></select>

我想根据所选的指标类型显示单位选择框的值。我需要帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用ng-change,如下所示

<select ng-model="selectedNotification.metricType" ng-options="metricType as metricType.metric for metricType in metricTypes" ng-change="units = selectedNotification.metricType.units"></select>

<select ng-model="selectedNotification.unit" ng-options="unit for unit in units"></select>

已将ng-options="metricType.metric as metricType.metric for metricType in metricTypes"更改为ng-options="metricType as metricType.metric for metricType in metricTypes"以获取完整的选定对象,并在ng-change中使用objectunits分配为selectedNotification.metricType.units < / p>

相关问题