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

导航模式异常及动态选项生成功能实现技术咨询

问题分析与解决方案

场景1:Navigation Mode 重复弹窗问题

你遇到的用户选择选项后需两次点击才进入详情页的问题,大概率是navigation-mode的配置或视图跳转逻辑出现了偏差。结合你提到的三个实现文件,我给你几个具体的排查和修复方向:

1. 确认navigation-mode的目标视图绑定

检查NewsChoice_Result.view.bxb中navigation-mode的target属性是否正确指向详情视图(NewsChoice_Details),而不是重复指向当前的选择视图。示例配置应该是这样:

navigation-mode {
  target: NewsChoice_Details
  confirmations: none
}

如果target设置错误,就会导致选择后重新加载当前视图,出现重复弹窗的情况。

2. 验证where-each的循环项绑定

在list-of中使用where-each时,要确保每个选项的value绑定了正确的唯一标识(比如新闻分类ID),这样选择后才能正确传递参数到详情页。例如:

list-of (newsCategories) {
  where-each (category) {
    layout-macro (NewsChoiceItem) {
      param (category) {expr(category)}
    }
  }
}

如果value没有正确绑定,系统可能无法识别用户的选择动作,进而重复触发选择界面。

3. 排查布局宏的交互配置

打开NewsChoice.layout.bxb的布局宏,确认每个选项的on-click或voice-command动作是否正确关联到详情意图。示例配置如下:

layout-macro (NewsChoiceItem) {
  params {
    param (category)
  }
  content {
    cell-card {
      content {
        text {
          value: {category.name}
          style (title)
        }
      }
      on-click {
        intent {
          goal: NewsChoice_Details
          value: {category.id}
        }
      }
    }
  }
}

如果on-click没有正确关联到详情意图,就会导致点击后无法跳转,停留在当前视图。


场景2:动态生成选项(从硬编码到用户输入驱动)

要实现根据用户输入(比如“英格兰”)动态生成球员选项,需要从NLU实体识别、数据获取、视图渲染三个核心环节改造:

1. 配置NLU识别用户输入的实体

先在你的NLU模型中添加Country实体,确保能准确识别用户提问中的国家名称(比如“英格兰”),这样在后续的action逻辑中就能获取到这个关键参数。

2. 修改news.js,替换硬编码为接口调用

把原来的固定选项逻辑,改成根据实体参数调用后端接口获取数据的动态逻辑:

// 替换硬编码的旧逻辑
// const newsOptions = ["体育新闻", "财经新闻", "综合新闻"];

// 新的动态数据获取逻辑
async function getPlayerOptions(country) {
  // 调用后端接口,传入country参数获取对应球员列表
  const response = await fetch(`/api/players?country=${country}`);
  const players = await response.json();
  // 返回前5个球员用于生成选项
  return players.slice(0, 5);
}

然后在action中调用这个函数,把获取到的球员数据传递给result-view。

3. 在Result View中动态渲染选项

修改NewsChoice_Result.view.bxb,让list-of使用动态传递的球员数据:

result-view {
  match: PlayerList (playerList)
  message {
    template ("请选择你想查看的球员:")
  }
  render {
    list-of (playerList) {
      navigation-mode {
        target: PlayerDetails
        confirmations: none
      }
      where-each (player) {
        layout-macro (PlayerChoiceItem) {
          param (player) {expr(player)}
        }
      }
    }
  }
}

同时在布局宏PlayerChoiceItem.layout.bxb中,支持语音选择序号或球员名称:

layout-macro (PlayerChoiceItem) {
  params {
    param (player)
  }
  content {
    cell-card {
      content {
        text {
          value: {player.name}
          style (title)
        }
      }
      voice-command {
        value: "{player.name}"
        intent {
          goal: PlayerDetails
          value: {player.id}
        }
      }
      on-click {
        intent {
          goal: PlayerDetails
          value: {player.id}
        }
      }
    }
  }
}

这样用户既可以点击选项,也可以通过语音说出球员名称或序号(系统默认支持序号选择,只要list-of配置正确)来跳转详情页。


如果按照上面的步骤调整后还有问题,可以告诉我你的navigation-mode具体配置或者action中的数据传递逻辑,我再帮你进一步排查。

内容的提问来源于stack exchange,提问作者Rahul Gupta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:02:56