我的数据结构是
$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>
我想根据所选的指标类型显示单位选择框的值。我需要帮助。
答案 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
中使用object
将units
分配为selectedNotification.metricType.units
< / p>