【问题标题】:How do I get jQuery UI autocomplete multiple to remove items that have already been selected如何让 jQuery UI 自动完成多个以删除已选择的项目
【发布时间】:2012-07-09 19:18:10
【问题描述】:

here 提供的 jQuery UI 自动完成多个示例允许您多次添加相同的项目。

如何防止这种情况发生?

【问题讨论】:

    标签: jquery jquery-ui autocomplete jquery-autocomplete jquery-ui-autocomplete


    【解决方案1】:

    如果以 jQuery UI here 提供的示例为例,请在自动完成的 select 函数中添加以下行:

    availableTags.splice($.inArray(ui.item.value, availableTags), 1);
    

    这基本上删除了刚刚从可用标签列表中选择的项目。

    你最终得到的选择函数应该是这样的:

    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( "" );
        this.value = terms.join( ", " );
        // remove added item from list of available items to select
        availableTags.splice($.inArray(ui.item.value, availableTags), 1);
        return false;
    }
    

    【讨论】:

    • 这很有帮助,为你 +1 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 2014-01-09
    相关资源
    最近更新 更多