我创建了一个JQuery UI Autocomplete,其中source是一个标签值对的数组。 我需要设置默认选中的项目。 我找到了一种方法,使用所需的标签,但如果我有VALUE而不是LABEL ,我怎么能这样做?
使用标签字符串设置默认值的代码:
$("myAutoCom").autocomplete("search", "someLabel"); var menu = $("myAutoCom").autocomplete("widget"); $(menu[0].children[0]).click();我有价值,而不是标签。 如何根据值设置所选项目? 提前致谢
i've created a JQuery UI Autocomplete in which the source is an array of label-value pairs. i need to set the default selected item. i found a way to do that using the desired label, but how can i do that if i have the VALUE instead of the LABEL?
code for setting default value using label string :
$("myAutoCom").autocomplete("search", "someLabel"); var menu = $("myAutoCom").autocomplete("widget"); $(menu[0].children[0]).click();i have the value,not the label. how can i set selected item depending on value? thanks in advance
最满意答案
因为我的自动完成源是一个包含所有标签值对的数组,并且因为我将该数组保存在全局变量中,所以我只是执行了以下操作:
在THAT数组中搜索给定值并返回相应的标签,然后使用该标签使用问题中提到的代码初始化自动完成。
感谢@ sepikas-antanas
since the source of my autocomplete is an array that contains all label-value pairs, and since i keep that array in a global variable, i just did the following:
searched THAT array for the given value and returned the corresponding label, then used that label to initialize the autocomplete using the code mentioned in the question.
thanks to @sepikas-antanas
更多推荐
标签,label,设置,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论