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

如何在XPages的djFilteringSelect控件中使用queryExpr设置查询模式

解决XPages djFilteringSelect任意位置匹配问题

要让djFilteringSelect支持输入内容匹配选项任意位置的字符,你之前的写法多嵌套了一层JavaScript表达式,这是问题所在。正确的queryExpr设置不需要用#{javascript:...}包裹,直接写模板字符串即可。

正确的queryExpr配置

<xe:this.queryExpr><![CDATA[*{0}*]]></xe:this.queryExpr>

这里的{0}会自动替换为用户输入的查询内容,*{0}*表示匹配任意位置包含查询词的选项,完全符合你要的效果。

完整可运行示例代码

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xe:djFilteringSelect id="djFilteringSelect1">
        <!-- 核心配置:开启任意位置匹配 -->
        <xe:this.queryExpr><![CDATA[*{0}*]]></xe:this.queryExpr>
        <!-- 测试选项 -->
        <xe:this.items>
            <xp:selectItem itemLabel="my name is x" itemValue="x"></xp:selectItem>
            <xp:selectItem itemLabel="this is a product" itemValue="product"></xp:selectItem>
            <xp:selectItem itemLabel="hello world" itemValue="hello"></xp:selectItem>
        </xe:this.items>
    </xe:djFilteringSelect>
</xp:view>

现在输入"x"就能显示"my name is x"选项,输入"product"也能匹配到对应的选项,完美实现任意位置的模糊搜索。

为什么之前的写法无效?

你之前用#{javascript:"*{0}*"}这种方式,系统会把整个字符串作为JavaScript代码执行,最终返回的是字符串*{0}*,但djFilteringSelect的queryExpr属性需要的是模板本身,不需要经过JavaScript解析,直接传递字符串模板即可。

内容的提问来源于stack exchange,提问作者Thomas Adrian

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 01:01:51