英文:
How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages
问题
我正在尝试调整XPages中的djFilteringSelect控件,以便当用户输入查询时,它可以找到字符序列的任何出现,而不仅仅是从开头开始。
所以,如果selectitems包含一个值"this is a product",而我输入"product",它应该是一个匹配。默认情况下,它只从文本的开头搜索。
有一个queryExpr属性可以用于此目的,但在XPages中使用的文档不足。我尝试了以下代码以及其他很多方法,但无法使其工作。
<xe:this.queryExpr><![CDATA[#{javascript:"*{0}*"}]]></xe:this.queryExpr>
<xe:this.queryExpr><![CDATA[#{javascript:"<xe:this.queryExpr><![CDATA[#{javascript:"*{0}*"}]]></xe:this.queryExpr>
<xe:this.queryExpr><![CDATA[#{javascript:"${0}*"}]]></xe:this.queryExpr>
*"}]]></xe:this.queryExpr>
以下是一个完整的示例,如果有人想复制/粘贴到新的XPage中,我想输入"x",然后条目"my name is x"应该显示出来。
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:djFilteringSelect id="djFilteringSelect1">
<xp:selectItem itemLabel="my name is x"></xp:selectItem>
<xp:selectItem itemLabel="my name is y"></xp:selectItem>
<xp:selectItem itemLabel="my name is z"></xp:selectItem>
</xe:djFilteringSelect>
</xp:view>
英文:
I am trying to tweak the djFilteringSelect control in XPages so that when a user type a query it finds any occurance of the char sequence, not just from the beginning.
so if the selectitems contain a value "this is a product" and I type product it should be a match. the default is that it only searches from the beginning of the text.
there is a queryExpr property that can be used for this but the documentation is lacking for use in XPages. I have tried the following and a lot others but cannot get it to work.
<xe:this.queryExpr><![CDATA[#{javascript:"*{0}*"}]]></xe:this.queryExpr>
<xe:this.queryExpr><![CDATA[#{javascript:"$*{0}*"}]]></xe:this.queryExpr>
<xe:djFilteringSelect id="djFilteringSelect1">
<xp:selectItems id="selectItems2">
<xp:this.value><![CDATA[#{javascript:var products = @DbLookup("","LookUp", "Produkt", 2);
products = @Unique(@Trim(products));
return products.sort();}]]></xp:this.value>
</xp:selectItems>
</xe:djFilteringSelect>
here is a complete example if anyone want to copy/paste into a new XPage, I want to type "x" and the entry "my name is x" should show up
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:djFilteringSelect id="djFilteringSelect1">
<xp:selectItem itemLabel="my name is x"></xp:selectItem>
<xp:selectItem itemLabel="my name is y"></xp:selectItem>
<xp:selectItem itemLabel="my name is z"></xp:selectItem>
</xe:djFilteringSelect>
</xp:view>
答案1
得分: 2
我们在应用程序中使用 djFilteringSelect
,它按预期工作。 唯一需要注意的是字符串中的一些字符必须进行转义:因此,queryExpr
的正确值是 "*\$\{0\}*"
。
关于为什么必须转义 $
和 {}
,可以在这里找到解释:https://xcellerant.wordpress.com/2014/07/22/changing-search-behavior-of-dojo-filtering-select-in-xpages/
英文:
We use djFilteringSelect
in our application and it's working as intented. The only point to note is that some characters in the string must be escaped: therefore the correct values for queryExpr
is "*\$\{0\}*"
.
The explanation why $
and {}
must be escaped can be found here https://xcellerant.wordpress.com/2014/07/22/changing-search-behavior-of-dojo-filtering-select-in-xpages/
答案2
得分: 1
djFilteringSelect
只是 Dojo FilteringSelect 组件的一个包装器,因此 queryExpr
和 searchExpr
仅用于传递给底层(客户端端)JavaScript 代码。因此,有关文档,Dojo 网站是一个很好的信息来源。根据 API 文档,*${0}*
应该是你想要的(https://dojotoolkit.org/api/?qs=1.6/dijit/form/FilteringSelect)。文档中提到了与 highlightMatch
结合使用以定义高亮显示的内容。
英文:
djFilteringSelect is just a wrapper for the Dojo FilteringSelect component, so queryExpr
and searchExpr
are just used to pass to the underlying (client-side) JavaScript code. So for documentation, Dojo site is a good source. According to the API documentation *${0}*
should do what you want (https://dojotoolkit.org/api/?qs=1.6/dijit/form/FilteringSelect). The docs talk about combining with highlightMatch to define what's highlighted.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论