gpt4 book ai didi

javascript - 如何配置 dojo.FilteringSelect 以匹配通配符值?

转载 作者:搜寻专家 更新时间:2023-11-01 04:11:48 34 4
gpt4 key购买 nike

下面是填充了用户数据的 filteringSelect 示例。我的目标是对显示的值执行通配符匹配。例如,如果用户键入“son”,则下拉匹配项将是“homer simpSON”和“carl calSON”。默认情况下,匹配只会出现在标签的开头。

我尝试更改 dijit.byId('userselect').searchAttr,但将其设置为字符串以外的任何内容会导致错误行为。

<input id="userselect">

<script type="text/javascript">
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");

var user_data = {
"itentifier":"user_id",
"label":"label",
"items":[
{"first_name":"Waylon","last_name":"Smithers","label":"Waylon Smithers","user_id":7}
,{"first_name":"Carl","last_name":"Carlson","label":"Carl Carlson","user_id":6}
,{"first_name":"Homer","last_name":"Simpson","label":"Homer Simpson","user_id":4}
,{"first_name":"Lenny","last_name":"Leonard","label":"Lenny Leonard","user_id":5}
,{"first_name":"Montgomery","last_name":"Burns","label":"Montgomery Burns","user_id":8}
]
};

dojo.addOnLoad(function() {
var userStore = new dojo.data.ItemFileReadStore({
//url: "/user/lookup",
data: user_data
});
var filteringSelect = new dijit.form.FilteringSelect({
id: "userselect",
name: "userselect",
store: userStore,
searchAttr: 'label' //["first_name", "last_name", "oasis"]
},
"userselect");
});
</script>

最佳答案

您需要设置 queryExpr 并将 autoComplete 设置为 false

var filteringSelect = new dijit.form.FilteringSelect({
id: "userselect",
name: "userselect",
store: userStore,
searchAttr: 'label',
queryExpr: '*${0}*',
autoComplete: false
},"userselect");

queryExpr 的 Dojo 文档:

This specifies what query is sent to the data store, based on what the user has typed. Changing this expression will modify whether the results are only exact matches, a "starting with" match, etc. dojo.data query expression pattern. ${0} will be substituted for the user text. * is used for wildcards.

${0}* means "starts with"
*${0}* means "contains"
${0} means "is"

关于javascript - 如何配置 dojo.FilteringSelect 以匹配通配符值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2805497/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com