jQuery tokeninput,第一次搜索不起作用 [英] Jquery tokeninput, first search doesn't work

查看:84
本文介绍了jQuery tokeninput,第一次搜索不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对tokeninput有一个奇怪的问题...

I have strange problem with tokeninput...

    $("[name='business_list']").tokenInput( {{businessList|raw}}, {
        hintText: "{{ 'business.findBusiness'|trans }}",
        noResultsText: "{{'no_results'|trans({},'app')|capitalize}}",
        searchingText: "{{'searching'|trans({},'app')|capitalize}}",
        prePopulate: {{businesses|raw}},
        onReady: function(){
            $("[name='business_list']").siblings(".token-input-list").find("#token-input-").focus();
        },
        onResult: function(items){
            items.push({
                value: "aaa",
                label: "<span>aaa</span>"
            })

            console.log(items);
            //return items;
        }
    });

它的工作原理是这样的: 例如,当我第一次键入"a"时,它显示无结果"(但是在控制台日志中,我可以看到他找到了7个对象).当我删除"a"并再次输入时,它可以正常工作.但是...当我输入例如"z"时,它将再次相同.它显示无结果",但我可以看到它找到了4个对象,并且在删除并再次键入后显示了它们... 有什么想法吗?

And it works like this: For example when I type 'a' for the first time it shows 'No results' (but in the console log I can see that he found 7 objects). When I delete 'a' and type it again it works fine. But... when I will type for example 'z' it will be again the same. It shows 'no results' but I can see that it founds 4 objects and after deleting and typing again it shows them... Any ideas ?

没有'onResult'函数,它可以正常工作,但是我想向任何结果中添加一个对象,但是这样做不起作用...

It works fine without 'onResult' function but I want to add one object to any result but with this it doesn't work fine...

推荐答案

问题已解决,代码:

$("[name='business_list']").tokenInput( {{businessList|raw}}, {
            hintText: "{{ 'business.findBusiness'|trans }}",
            noResultsText: "{{'no_results'|trans({},'app')|capitalize}}",
            searchingText: "{{'searching'|trans({},'app')|capitalize}}",
            prePopulate: {{businesses|raw}},
            onReady: function(){
                $("[name='business_list']").siblings(".token-input-list").find("#token-input-").focus();
            },
            onResult: function(items){
                var value = $('#token-input-').val();
                items.push({
                    label: "<span class='new-business'><img src='{{ asset('bundles/cloudcrm/images/business.png') }}' style='margin-right: 5px;'>{{ 'deals.newDeal.addBusiness'|trans({},'crm')|capitalize }}<strong>" + " " + value + "</strong></span>",
                    id: "new",
                    value: value
                });
                return items;
            },
            onAdd: function(item){
                if( $(item.label).hasClass("new-business") == true ){
                    $("[name='business_list']").tokenInput("remove", item);
                    $(".modal-business-add").modal('show');
                }
            }
        });

这篇关于jQuery tokeninput,第一次搜索不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆