【问题标题】:Splunk Dashboard. Multiselect depends on another multiselectSplunk 仪表板。多选依赖于另一个多选
【发布时间】:2021-12-20 10:25:48
【问题描述】:

我试图让一个 multiselect 依赖于另一个 multiselect。当我选择Opt1 时,我已经到了显示另一个多选的地步。这就是我想要的。但我也希望在选择Opt1Opt2 时出现multiselect2

如果我先选择Opt1,然后选择Opt2,则会显示第二个多选。但不是当我选择Opt2 然后Opt1。那么如何让第二个multiselect 也出现?

<form theme="dark">
    <label>concept</label>
    <fieldset submitButton="true" autoRun="false">
        <input type="multiselect" token="index">
            <label>Index</label>

            <choice value="opt1">Opt1</choice>
            <choice value="opt2">Opt2</choice>

            <change>
                <condition value="opt2">
                    <unset token="opt1_selected"></unset>
                </condition>

                <condition value="opt1">
                    <set token="opt1_selected"></set>
                </condition>
            </change>

            <delimiter> OR </delimiter>
            <default>Opt1</default>
        </input>

        <input type="multiselect" token="Menu2" depends="$opt1_selected$">
            <label>Multi2</label>
        </input>
    </fieldset>
</form>

【问题讨论】:

    标签: splunk-dashboard


    【解决方案1】:

    根据经验,我发现当submitButton 属性设置为true 时,使用令牌并不是那么简单。

    除非提交按钮对您的用例很重要,否则请参阅下面的简单 XML 代码,我将该属性转换为 false

    <form theme="dark">
      <label>Sample</label>
      <init>
        <set token="show">true</set>
      </init>
      <fieldset submitButton="false" autoRun="false">
        <input type="multiselect" token="index">
          <label>Index</label>
          <choice value="opt1">Opt1</choice>
          <choice value="opt2">Opt2</choice>
          <change>
            <condition match="match($index$,&quot;opt1&quot;) OR match($index$,&quot;opt2&quot;)">
              <set token="show">true</set>
            </condition>
            <condition match="NOT match($index$,&quot;opt1&quot;) OR match($index$,&quot;opt2&quot;)">
              <unset token="show">true</unset>
            </condition>
          </change>
          <delimiter> OR </delimiter>
          <default>opt1</default>
        </input>
        <input type="multiselect" token="Menu2" depends="$show$">
          <label>Multi2</label>
        </input>
      </fieldset>
    </form>
    

    此解决方案应使用以下值组合: opt1, opt1 OR opt2, opt2,和 opt2 OR opt1.

    解释:

    诀窍在于评估 index 令牌,它包含 final 选择值。您可以在&lt;condition&gt; 标签内使用match 属性,它允许您使用类似eval 的表达式来验证令牌。

    ...
    <condition match="match($index$,&quot;opt1&quot;) OR match($index$,&quot;opt2&quot;)">
       <set token="show">true</set>
    </condition>
    ...
    

    此表达式的逻辑是将输入字符串(令牌index 的值)与正则表达式(opt1opt2)“匹配”或比较。请注意,要使此表达式起作用,您必须使用 HTML entities 转义一些字符(例如,将引号转换为 &amp;quot;)。

    如果找到匹配,则满足条件,将继续执行令牌show的设置。

    ...
       <set token="show">true</set>
    ...
    

    否则,它将继续评估下一个条件(基本上是相同的表达式,但用 NOT 运算符取反),然后继续取消设置令牌show

    ...
    <condition match="NOT match($index$,&quot;opt1&quot;) OR match($index$,&quot;opt2&quot;)">
       <unset token="show">true</unset>
    </condition>
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-09
      • 2018-11-26
      • 1970-01-01
      • 2019-03-08
      • 2012-01-30
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      相关资源
      最近更新 更多