如何将属性传递给autocomplete()函数?

时间:2019-02-08 22:17:27

标签: jquery autocomplete jquery-ui-autocomplete

我有几个输入字段:

<input  type="text" name="product_1" value=""  id="input-pricebyproduct"/>product-1</input>
<input  type="text" name="product_2" value=""  id="input-pricebyproduct"/>product-2</input>
<input  type="text" name="product_3" value=""  id="input-pricebyproduct"/>product-3</input>

如何通过名称属性将变量传递给autocomplete()?

<script type="text/javascript"><!--

    $('input[name="product"]').autocomplete({
        source: function(request, response) {
            $.ajax({
                url: 'index.php?route=extension/module/price_autoupdate/autocomplete&user_token={{ user_token }}&filter_product=' +  encodeURIComponent(request),
                dataType: 'json',
                success: function(json) {
                    response($.map(json, function(item) {
                        return {
                            label: item['name'],
                            value: item['product_id']
                        }
                    }));
                }
            });
        },
        select: function(item) {
            $('input[name=\'product\']').val('');

            $('#input-product' + item['value']).remove();

            $('#input-product').append('<div id="input-product' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="module_price_autoupdate_product[]" value="' + item['value'] + '" /></div>');
        }
    });

    $('#input-product').delegate('.fa-minus-circle', 'click', function() {
        $(this).parent().remove();
    });
//--></script>

我对此一无所知,找不到解决方法...

我已经尝试过了:

var key = $("#input-pricebyproduct").attr('name');

 $('input[name=" + key + "]').autocomplete({
 //the rest stuff
    });

但是似乎丢失了一些东西,此解决方案无法正常工作... 我只能从第一个输入获取属性。该如何解决?

0 个答案:

没有答案