我一直在四处张望,却找不到答案。我可以让JQuery Easyautocomplete(http://easyautocomplete.com/)与Links一起工作,然后使其与图像一起工作,但是我似乎无法使其与两者一起工作。我是JavaScript新手。我不确定自己在做什么错。
这是我的代码...

var options = {
    data: [
        {
            "text": "Home",
            "website_link": "http://easyautocomplete.com/",
            "icon": "http://lorempixel.com/100/50/transport/6"
        },
        {
            "text": "Github",
            "website_link": "https://github.com/pawelczak/EasyAutocomplete",
            "icon": "http://lorempixel.com/100/50/transport/6"
        }
    ],

    getValue: "text",

    template: {
        type: "custom",
        fields: {
            website_link: "website_link"
        },
        method: function(value, item) {
            return "<a href=" website_link "><img src='" + item.icon + "' />" + value + "</a>";
        }
    }
};
jQuery("#loan-officer-select").easyAutocomplete(options);
我在这里做错了什么?任何帮助将不胜感激。

最佳答案

检查这是否是你想要的

    var options = {
    data: [
        {
            "text": "Home",
            "website_link": "http://easyautocomplete.com/",
            "icon": "http://lorempixel.com/100/50/transport/6"
        },
        {
            "text": "Github",
            "website_link": "https://github.com/pawelczak/EasyAutocomplete",
            "icon": "http://lorempixel.com/100/50/transport/6"
        }
    ],

    getValue: "text",

    template: {
        type: "custom",
        method: function(value, item) {
            return `<div>
              <img src="${item.icon}" width="50px" height="50px" />
              <a href=${item.website_link}> click me to go to ${value}</a>
           </div>`;
        }
    }
};
jQuery("#loan-officer-select").easyAutocomplete(options);

09-27 21:48