How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages

huangapple go评论49阅读模式
英文:

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>

How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages

How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages

英文:

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.

&lt;xe:this.queryExpr&gt;&lt;![CDATA[#{javascript:&quot;*{0}*&quot;}]]&gt;&lt;/xe:this.queryExpr&gt;
&lt;xe:this.queryExpr&gt;&lt;![CDATA[#{javascript:&quot;$*{0}*&quot;}]]&gt;&lt;/xe:this.queryExpr&gt;
&lt;xe:djFilteringSelect id=&quot;djFilteringSelect1&quot;&gt;
&lt;xp:selectItems id=&quot;selectItems2&quot;&gt;
	&lt;xp:this.value&gt;&lt;![CDATA[#{javascript:var products = @DbLookup(&quot;&quot;,&quot;LookUp&quot;, &quot;Produkt&quot;, 2);
products = @Unique(@Trim(products));
return products.sort();}]]&gt;&lt;/xp:this.value&gt;
						&lt;/xp:selectItems&gt;
&lt;/xe:djFilteringSelect&gt;

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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;xp:view xmlns:xp=&quot;http://www.ibm.com/xsp/core&quot;
	xmlns:xc=&quot;http://www.ibm.com/xsp/custom&quot;
	xmlns:xe=&quot;http://www.ibm.com/xsp/coreex&quot;&gt;
	
	&lt;xe:djFilteringSelect id=&quot;djFilteringSelect1&quot;&gt;
		
		&lt;xp:selectItem itemLabel=&quot;my name is x&quot;&gt;&lt;/xp:selectItem&gt;
		&lt;xp:selectItem itemLabel=&quot;my name is y&quot;&gt;&lt;/xp:selectItem&gt;
		&lt;xp:selectItem itemLabel=&quot;my name is z&quot;&gt;&lt;/xp:selectItem&gt;
	&lt;/xe:djFilteringSelect&gt;
&lt;/xp:view&gt;

How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages

How to set a query pattern using the queryExpr property in the djFilteringSelect control in XPages

答案1

得分: 2

我们在应用程序中使用 djFilteringSelect,它按预期工作。 唯一需要注意的是字符串中的一些字符必须进行转义:因此,queryExpr 的正确值是 &quot;*\$\{0\}*&quot;

关于为什么必须转义 ${},可以在这里找到解释: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 &quot;*\$\{0\}*&quot;.

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 组件的一个包装器,因此 queryExprsearchExpr 仅用于传递给底层(客户端端)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.

huangapple
  • 本文由 发表于 2023年2月16日 18:45:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定