简体   繁体   English

在循环JavaScript上附加参数

[英]Append param on loop javascript

I have a function that has a menu param 我有一个具有menu参数的功能

removeChildCheck:function(menu){
    let removeArrayValues = [];
       for(var i=0; i < this.checkbox.menu.length; i++){
           removeArrayValues.push(this.checkbox.menu[i].value);
       }
       this.user.permissions = this.user.permissions.filter((i) => !removeArrayValues.includes(i));
 },

when I used it like this removeChildCheck('dashboard') im getting length of undefined. 当我像这样使用removeChildCheck('dashboard')我正在获得未定义的长度。

How can I append the param and loop on it? 如何附加param并在其上循环? TIA TIA

Do you mean to do: 您的意思是:

this.checkbox[menu]

That is, access the property of checkbox that has the name stored in the variable menu ? 即,访问名称存储在变量menu ?中的checkbox的属性。 Keep in mind that: 请记住:

this.checkbox.dashboard

is equivalent to 相当于

this.checkbox['dashboard']

and

menu = 'dashboard'
this.checkbox[menu]

As audiodude says, use array syntax: this. 正如audiodude所说,请使用数组语法:this。 checkbox[menu] .length 复选框[菜单] .length

removeChildCheck:function(menu){
    let removeArrayValues = [];
       for(var i=0; i < this.checkbox[menu].length; i++){
           removeArrayValues.push(this.checkbox[menu][i].value);
       }
       this.user.permissions = this.user.permissions.filter((i) => !removeArrayValues.includes(i));
 },

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM