jQuery TokenInput : Tokens are not getting added

丶灬走出姿态 提交于 2019-12-02 05:51:28

问题


I am using jQuery TokenInput which calls the service written in node.js. The service is giving me a response. (I have logged it in onResult and resultsFormatter.) But the drop down of tokens doesn't show up.

My service response is as follows:

{
    "data": [
        {
            "name": "a",
            "key": 1023040,
            "subtext": "abc"
        },
        {
            "name": "b",
            "key": 1023040,
            "subtext": "pqr"
        }
    ]
}

JavaScript code is as follows.

       $("#myInputTextBox").tokenInput('http://myWebService', {
            crossDomain: true,
            theme: "facebook",
            minChars: 3,
            resultsFormatter: function(item) { 
                console.log("<li><p class='added' data-id='" + 
                            item.key + "' data-name='" + item.originalName + 
                            "'>" + item.name + "</p></li>");
                return "<li><p class='added-cities' data-id='" + 
                item.key + "' data-name='" + item.originalName + 
                "'>" + item.name + "</p></li>" 
            }, 
            onResult: function (results) {
                 results = results["data"];
                 $.each(results, function (index, value) {
                        value.originalName = value.name;
                        value.id = value.key;
                        value.name = value.name + " " + value.subtext;
                 });
                console.log(results);
                return results;
            },
            onAdd: function(item) {
                console.log("addrd");
            }
        });

The response is getting logged in onResult as well as resultsFormatter as expected. I tried to log it in onAdd it doesn't get logged. What's the issue here?


回答1:


The issue here is likely due to the face that the TokenInput is being used in a modal window, and the z-index of the dropdown is 1, whereas the modal window will likely be higher.

To fix this the z-index value in token-input.css for div.token-input-dropdown should be modified to be higher than the modal value.



来源:https://stackoverflow.com/questions/23677002/jquery-tokeninput-tokens-are-not-getting-added

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!