Populate JQuery TokenInput on AJAX event

2019-09-21 12:21发布

问题:

Let say a jQuery TokenInput is attached with a text field with a pre populate parameter defined during its initialization.

Now I want to populate that input field with some tokens on an event trigger without re-initialization of this plugin.

回答1:

I have found the solution of my work. Thats why I am posting here so that others can benefit from this answer.

Let say Occupation is my field with id "occupation".

$("#occupation").tokenInput("add", {id: 1, name: "Software Engineer"});

"add" is a function which adds the json record as a token on the fly.

Hope it helps.

Thanks