Jump to content
  • 0

easyautocomplete


d0ublezer0
 Share

Question

Пытаюсь использовать http://easyautocomplete.com/ для подстановки значений в поле ввода

На странице может быть несколько полей с одинаковыми данными, пытаясь охватить их все, я написал вот такой код:

    $("#city_selector_suggest").easyAutocomplete({
        url: "/templates/rm/js/ecity2.json",

        getValue: function(element) {
            return element.cdek_cityname;
        },

        list: {
            onChooseEvent: function() {
                var selectedItemValue = $(this).getSelectedItemData().cdek_id;
                console.log(selectedItemValue);
            },
            onHideListEvent: function() {
                $(this).val("").trigger("change");
            },
            match: {
                enabled: true,

                method:  function(element, phrase) {
                    if(element.indexOf(phrase) === 0) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        },
        theme: "bootstrap",
        placeholder: "Введите ваш город"
    });

данные в файле ecity2.json примерно такого вида:

[
{"cdek_id":"15503","cdek_cityname":"Армянск","post_code":"296012"},
{"cdek_id":"5214","cdek_cityname":"Бахчисарай","post_code":"298400"},
{"cdek_id":"6874","cdek_cityname":"Джанкой","post_code":"296100"},
]

Так вот вопрос - как сделать так, чтобы при выборе элемента из предлагаемого списка всегда возвращалось значение этого элемента? В данном случае мне нужно достать cdek_id

У меня $(this) всегда undefined

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy