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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top