如何删除文本框上的自动建议功能

发布于 2024-12-06 16:13:35 字数 1159 浏览 0 评论 0原文

我有一个文本框,我想根据单选按钮选项加载 2 自动建议

意味着如果用户选择选项按钮 1,则自动建议应加载产品员工表。如果用户选择选项按钮 2,则自动建议应加载自定义产品表。

我正在使用 jquery auto suggest

我怎样才能实现这种功能

示例 当我选择单选按钮 SetAutoSuggest 方法将被调用

   function SetAutoSuggest(ProductType) {

    if (ProductType == "PRODUCT") {

        $("#PantryFooodItemName").autocomplete('<%= Url.Action("GetAutosuggestProductlistForMeal", "Autosuggest") %>',
            {
                minChars: 2,
                width: 300,
                multiple: false,
                matchContains: true,
                mustMatch:true,
                formatItem: formatItem,
                formatResult: formatResult
            }
            );





}
if (ProductType == "CUSTOMPRODUCT") {
    $("#PantryFooodItemName").autocomplete('<%= Url.Action("GetCustomProduct", "Autosuggest") %>',
            {
                minChars: 2,
                width: 300,
                multiple: false,
                matchContains: true,
                mustMatch: true,
                formatItem: formatItem,
                formatResult: formatResult
            }
            );

}
    }

I have one text box and i want load 2 auto suggest basis on radio button option

Means if user select option button 1 then auto suggest should load Product employee table.if User select option button 2 then auto suggest should load Custom Product table.

I am using jquery auto suggest

How could i achieve this kind of functionality

Example for
when i select radio button SetAutoSuggest Method Will be called

   function SetAutoSuggest(ProductType) {

    if (ProductType == "PRODUCT") {

        $("#PantryFooodItemName").autocomplete('<%= Url.Action("GetAutosuggestProductlistForMeal", "Autosuggest") %>',
            {
                minChars: 2,
                width: 300,
                multiple: false,
                matchContains: true,
                mustMatch:true,
                formatItem: formatItem,
                formatResult: formatResult
            }
            );





}
if (ProductType == "CUSTOMPRODUCT") {
    $("#PantryFooodItemName").autocomplete('<%= Url.Action("GetCustomProduct", "Autosuggest") %>',
            {
                minChars: 2,
                width: 300,
                multiple: false,
                matchContains: true,
                mustMatch: true,
                formatItem: formatItem,
                formatResult: formatResult
            }
            );

}
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぇ气 2024-12-13 16:13:35

将点击事件分配给复选框,并根据选中的复选框更改您的 URL。

或者,您可以在自动完成源上使用回调函数,该函数将验证选中了哪个复选框并提取正确的源 URL。
使用回调函数时遇到的最大问题是它需要非常严格的格式:

source: function(request, response)
{}

响应应该采用以下格式:

[{"id":25,"label":"mylabel","value":"myval"},{"id":26,"label":"mylabel26","value":"myval26"}]

使用单选按钮来代替您想要执行的操作不是更好吗?
这听起来像是您试图执行非此即彼而不是多选项(复选框)的情况。

Assign click events to the checkboxes and change your URL based on which one is checked.

Alternatively, you can use a callback function on the autocomplete source which would verify which checkbox is checked and pull the proper source url.
The biggest thing you'll run into using the callback function is it requires a very strict format:

source: function(request, response)
{}

Response should be in this format:

[{"id":25,"label":"mylabel","value":"myval"},{"id":26,"label":"mylabel26","value":"myval26"}]

Wouldn't it be better to use a radio button for what you're trying to do instead?
It sounds like a situation where you're trying to do an either/or and not a multi-option (checkboxes).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文