JQuery plugin: using callback to change plugin behavior

I use the jQuery plugin to input tokens and would like to change its behavior when adding a token.

I added the onAddToken callback to the source code so that I can see when the token is added to the input field, but I'm not sure how to change the tokenInput url from "url / to / call" to the new URL, "new / url / to / call ".

this , $ this and $ (this) don't seem to work. Any suggestions?

$("#input").tokenInput("/url/to/call", {
        noResultsText: "No results yet. Type some more...",
        searchingText: "Searching...",
        onAddToken: function(args) {
            // alter tokenInput itself to use "new/url/to/call" instead of 
            // the original "url/to/call/"
    }
 });
+3
source share
1 answer

, , (, ..), () . , , javascript - .

callsite ( ) :

config.onAddToken({url: myUrlVar});

url .

$("#input").tokenInput("/url/to/call", {
        noResultsText: "No results yet. Type some more...",
        searchingText: "Searching...",
        onAddToken: function(oUrl) {
            oUrl.url = "mynew/url";
        }
});

, , , , , url, , , .

callsite:

myUrlVar = config.onAddToken(myUrlVar);

:

$("#input").tokenInput("/url/to/call", {
        noResultsText: "No results yet. Type some more...",
        searchingText: "Searching...",
        onAddToken: function(oUrl) {
            return "mynew/url";
        }
});

, :

var newUrlVar = config.onAddToken(myUrlVar);
if(newUrlVar)
    myUrlVar = newUrlVar;

, .

+3

Source: https://habr.com/ru/post/1721837/


All Articles