简体   繁体   English

在数组项中添加图像-JavaScript

[英]Adding image in Array Item - JavaScript

How to add a image in array item (that will be pushed to Autocomplete) with JavaScript / jQuery? 如何使用JavaScript / jQuery在数组项中添加图像(将被推送到自动完成功能)?

Hello, I'm trying to learn JS by myself and I'm having a lot of issues. 您好,我正在尝试自己学习JS,并且遇到了很多问题。 Now I will just explain one of them. 现在,我将解释其中之一。

I have jQuery Autocomplete in one text input, I want to display a message when don't have the autocomplete results. 我在一个文本输入中具有jQuery自动完成功能,但是我想在没有自动完成功能结果时显示一条消息。 Now I just show a message (working), but I want to add a GIF loading image. 现在,我仅显示一条消息(正在运行),但是我想添加一个GIF加载图像。


My code: 我的代码:

$("input[type=search]").autocomplete({
                delay: 0,
                source: function(request, response) {
                    populate(request.term, response);

                    result = $.ui.autocomplete.filter(result, request.term)

                    // Just prevent to add a lot of "loading" itens to result.
                    for (var i in result){
                        if (i.item.type == "loading"){
                            result.splice(i, 1);
                        }

                        var item = {};
                        item.type = 'loading'
                        item.label = "Loading.."
                        item.value = "Loading.."
                        result.push(item)
                    }
                    response(result)
                }  

What can I do to display a GIF with this code? 如何显示此代码的GIF?

------- Edit: ------- 编辑:
Now I tested the code (this code is a new one) and it's appear don't work. 现在,我测试了该代码(此代码是新代码),但似乎不起作用。 What can be the problem? 可能是什么问题?

just make sure the code in the source part is correct.This is just a basic module about how to go about things. 只需确保源代码中的代码正确即可。这只是关于如何处理事情的基本模块。

 $("input[type=search]").autocomplete({
    delay: 0,
    source: function (request, response) {
        populate(request.term, response);
        //your stuff
    }.data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li />")
            .data("item.autocomplete", item)
            .append("<a><img src='" + your - path + "' />" + your value + "</a>")
            .appendTo(ul);
    };
});

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

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