简体   繁体   English

JQuery 选择自动完成问题

[英]JQuery Chosen autocomplete issue

I have a list of product (about 18000) so I like to load some of them with the autocomplete when user tape SI have item contain S我有一个产品列表(大约 18000 个),所以我喜欢在用户磁带 SI 有项目包含 S 时使用自动完成加载其中一些

here is my code这是我的代码

 <div class="chzn-panel">
                                <select id="nomenclature_pv_recherche" name="nomenclature_pv_recherche" data-placeholder="<?php echo  JText::_('COM_TKTRANSIT_DOSSIER_PV_NOMENCLATURE'); ?>" class="chzn-select-deselect"  style="width: 256px;">
                                    <?php 
                                        //echo JHtml::_('select.options', TkTransitHelper::getOptionsWithFieldName('nomenclature',"code",JText::_('COM_TKTRANSIT_DOSSIER_PV_NOMENCLATURE_OPTION')),'value', 'text', '');
                                        //echo JHtml::_('select.options', array(),'value', 'text', '');  
                                    ?>
                                    <option value="">- Select Option -</option>
                                </select>
                            </div>
                            <script type="text/javascript"> 
                                $("#nomenclature_pv_recherche").chosen({allow_single_deselect:true}); 
                            </script>

and for Javascript I have this对于 Javascript 我有这个

$("#nomenclature_pv_recherche").chosen();
        $('#nomenclature_pv_recherche input').autocomplete({
            source: function( request, response )
            {
                alert(request);
                alert(response);
                $.ajax({
                    url:  'index.php?option=com_tktransit&task=privileges_fiscaux.getNomenclatureWithString',
                    data: {nomenclature:request.term},
                    dataType: "json",
                    success: function( data )
                    {
                        $('#nomenclature_pv_recherche').empty();
                        response( $.map( data, function( item )
                        {
                            $('#nomenclature_pv_recherche').append('<option value="'+item.id+'">' + item.code + '</option>');

                        }));
                        $("#nomenclature_pv_recherche").trigger("chosen:updated");
                    }
                });
            }
        });

I don't know why I have no alert, no Ajax applet我不知道为什么我没有警报,没有 Ajax 小程序

What's wrong?怎么了?

Jquery 3.5.1 JqueryUI 1.12.1 chosen 1.8.7 Thank you Jquery 3.5.1 JqueryUI 1.12.1 选择 1.8.7 谢谢

$("#tags")
// don't navigate away from the field on tab when selecting an item
.on("keydown", function(event) {
    if (event.keyCode === $.ui.keyCode.TAB &&
        $(this).autocomplete("instance").menu.active) {
        event.preventDefault();
    }
})
.autocomplete({
    minLength: 0,
    source: function(request, response) {
        // delegate back to autocomplete, but extract the last term
        response($.ui.autocomplete.filter(
            availableTags, extractLast(request.term)));
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    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(", ");
        return false;
    }
});

You can see DEMO 你可以看DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM