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

如何在Ruby查询中添加静态值实现全选客户端选项

解决方案

要在客户列表中添加静态的“ALL(全选)”选项,只需在构建客户列表字典时插入该静态选项,同时修正原代码中的语法错误即可,具体实现如下:

修改后的完整代码

tipo = $evm.root['dialog_param_type']
option = $evm.root['dialog_param_action']
dialog_field = $evm.object

if tipo == "ALL"
  puts option
  dialog_field['read_only'] = "true"
  $evm.object['values'] = {1 => "-- Please select an option from above --"}
else
  puts option
  dialog_field['read_only'] = "false"
  customer_list = {}

  # 添加静态"ALL(全选)"选项,用'ALL'作为标识key,可根据需求替换为0或其他值
  customer_list['ALL'] = "ALL(全选)"

  # 修正原代码循环语法错误,正常遍历数据库查询结果
  get_query($evm.object.decrypt('query')).each do |item|
    customer_list["#{item['customer_id']}"] = item['customer_name'].to_s
  end

  dialog_field['values'] = customer_list
end

关键修改说明

  • 提前插入静态选项:在初始化customer_list后直接添加customer_list['ALL'] = "ALL(全选)",该选项会默认显示在列表顶部;若需要放在列表末尾,可将此代码移到遍历客户数据之后。
  • 修正循环语法错误:移除原代码each循环块参数中错误的赋值语句,改为正确的|item|来遍历查询结果。
  • 修正字典key格式:删除原代码中customer_list的key里多余的, Customer id: *部分,仅保留客户ID作为唯一标识。

内容的提问来源于stack exchange,提问作者miguel lara

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 13:55:18