简体   繁体   English

范围值更改时如何过滤角度md-option中的下拉列表

[英]How to filter dropdown list in angular md-option when scope value is changing

I have a dropdown menu using with the data array 我有一个与数据数组一起使用的下拉菜单

data = [{type:"day", value:"daily"}
        ,{type:"hour", value:"hourly"}
         ,{type:"month", value:"monthly"}] 

and also i have flag in my environment variable as 而且我在我的环境变量中有标记为

enableHourly = "true"
enableDaily = "true"
enableMonthly = "true"

by setting one of the value in false the value should be change like 通过将值之一设置为false,值应该像

if enableHourly = "false" 如果enableHourly =“ false”

in the md-options select should only display day and month 在md-options中选择应仅显示日期和月份

this is what i try but it seems its not working atm. 这是我尝试的方法,但似乎无法正常工作。

self.timeExecutionList = () => {
            // check if hourly, daily, weekly, monthly tag is true or false string then remove to
            // the array
            if (self.beebotCreate) {
                var arr = self.timeTypeList;
                for( var i = 0, n = arr.length; i < n; i++){ 
                    if (arr[i].includes('hr') && self.beebotRunHourly !== "true") {
                      arr.splice(i, 1); 
                    }

                    if (arr[i].type === 'day' && self.beebotRunTimeOfDay !== "true") {
                        arr.splice(i, 1); 
                    }

                    if (arr[i].type === 'week' && self.beebotRunMonthly !== "true") {
                        arr.splice(i, 1); 
                    }

                    if (arr[i].type === 'month' && self.beebotRunMonthly !== "true") {
                        arr.splice(i, 1); 
                    }
                    i--
                 }

                return arr
}

if you have cleaner solution would be appreaciated 如果您有更清洁的解决方案,我们将不胜感激

I feel you could add the boolean value to the data field with default settings and make use of the boolean variable to populate the dropdown. 我觉得您可以使用默认设置将布尔值添加到数据字段中,并利用布尔变量来填充下拉列表。 slicing array is expensive. 切片阵列很昂贵。

data = [{type:"day", value:"daily", "enabled" : true}
        ,{type:"hour", value:"hourly","enabled" : true}
        ,{type:"month", value:"monthly", "enabled" : true}]

In html, for all options, if the flag is set to true, add it to dropdown else not. 在html中,对于所有选项,如果该标志设置为true,则将其添加到下拉列表中,否则不添加。 Hope that helps 希望能有所帮助

<md-select> 
     <div ng-repeat="type in data" >
     <md-option *ngIf="type.enabled" ng-value="{{value}}">
          {{type.value}}
     </md-option>
     </div>
</md-select>`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 md-select 和 md-option 的 Angular Material 下拉菜单不显示 - Angular Material dropdown using md-select and md-option doesn't display 如何在中设置选项值 <md-option> 的 <md-select> 从控制器使用AngularJS? - How to set an option value in <md-option> of <md-select> from controller using AngularJS? 角度+材质自动完成:如何仅将某些值绑定到md-option中的模型 - Angular + Material Autocomplete: How to bind certain values only to model in md-option md-select和md-option与if - md-select and md-option with if 当我更改下拉列表中的状态时,它会更改angular js中实际范围中的值 - when I am changing the status in dropdown , its changing the value in actual scope in angular js ng-repeat不填充md-option的值 - ng-repeat not populating values at md-option jQuery-根据下拉列表中的选项更改复选框值 - Jquery - changing checkbox value depending on option from Dropdown list 如何使用“新值”选项创建下拉列表? - How to create dropdown list with “new value” option? AngularJS-使用文本框过滤下拉列表并提交选项值 - AngularJS - Filter Dropdown List with text box and submit option value 当选定的选项更改Java脚本时,选定的下拉值不变 - Dropdown Value selected not changing when option selected changes Java Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM