【问题标题】:How to loop through the option set in js如何遍历js中设置的选项
【发布时间】:2021-08-12 03:54:11
【问题描述】:

我正在使用 javascript 设置选定值的选项。我已经将它放在一个变量中,但需要循环访问该变量,如果循环包含列表中的一个特定值,则执行一个操作。

        var formContext = executionContext.getFormContext();
        let selectedItem = formContext.getAttribute("currentactivity").getValue();
        alert(selectedItem);
        if(selectedItem == 8)){
            formContext.getControl("currentcomments").setVisible(true);
        } else
        {
            formContext.getControl("currentcomments").setVisible(false);
        }

在此,所选项目将具有 (0-8) 之间的值列表。我的代码只是查看第一个值并没有遍历所有值。

你们中有人可以指导我吗

【问题讨论】:

标签: javascript dynamic-programming


【解决方案1】:

你可以修改这个:

for(var index = 0;index

【讨论】:

  • for(var index = 0;index
【解决方案2】:

我使用了 Array.prototype.includes(),它成功了。

if( selectedItem.includes(8))
    {
        formContext.getControl("currentcomments").setVisible(true);
    } else
    {
        formContext.getControl("currentcomments").setVisible(false);
    }

【讨论】:

    猜你喜欢
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多