[英]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.