You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Splunk经典仪表盘如何根据前置单选输入动态显隐后续单选选项

Splunk Classic仪表盘二级单选选项动态显隐实现方案

完全可以通过Splunk原生的token机制+depends属性实现需求,不需要编写自定义前端JS,兼容所有支持Classic仪表盘的Splunk版本。

实现逻辑

  • 一级环境选择单选框切换选项时,自动设置对应区域的标识token,同时清空其他区域的标识token,避免选项串显
  • 二级子环境单选框的每个选项单独配置depends属性,仅当对应标识token存在时,该选项才会渲染显示
  • 切换一级选项时自动重置二级单选框的选中值为All,避免选中已隐藏的无效选项导致搜索逻辑异常

可直接替换使用的完整代码

<form>
  <label>tst2</label>
  <fieldset>
    <input type="radio" token="environment">
      <label>ENV</label>
      <choice value="US">USA</choice>
      <choice value="Asia">APAC</choice>
      <choice value="UAE">UAE</choice>
      <default>US</default>
      <change>
        <unset token="sub-environment1"></unset>
        <unset token="show_us"></unset>
        <unset token="show_asia"></unset>
        <unset token="show_uae"></unset>
        <condition value="US">
          <set token="show_us">true</set>
          <set token="sub-environment1">*</set>
        </condition>
        <condition value="Asia">
          <set token="show_asia">true</set>
          <set token="sub-environment1">*</set>
        </condition>
        <condition value="UAE">
          <set token="show_uae">true</set>
          <set token="sub-environment1">*</set>
        </condition>
      </change>
    </input>
    <input type="radio" token="sub-environment1">
      <label>S-ENV</label>
      <choice value="*">All</choice>
      <choice value="NewYork" depends="$show_us$">NY</choice>
      <choice value="LA" depends="$show_us$">LA</choice>
      <choice value="Washington" depends="$show_us$">WT</choice>
      <choice value="Delhi" depends="$show_asia$">DL</choice>
      <choice value="Mumbai" depends="$show_asia$">MB</choice>
      <choice value="Tokio" depends="$show_asia$">TK</choice>
      <choice value="Dubai" depends="$show_uae$">DB</choice>
      <choice value="Abu-Dabhi" depends="$show_uae$">ABD</choice>
    </input>
  </fieldset>
</form>

注意要点

  • depends属性直接加在单个<choice>标签上,而非整个二级input标签上,这是实现单选项级别显隐的核心
  • 代码默认初始选中USA区域,二级选项默认选中All,如需调整初始值,修改<default>标签对应的value即可
  • 所有逻辑为Splunk原生支持,无版本兼容问题,不需要额外开启功能开关

内容的提问来源于stack exchange,提问作者Boya Raghavendra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 10:54:15