I am trying to get the JQuery Token Input prepopulated.
var assignUserJson=$('#assignUserJson').val();
console.log(assignUserJson); //[{"id":"1","name":"Andrew"},{"id":"3","name":"John"}]
Here is a difference between two ways that I supposed it should work in:
$('#assignTask').tokenInput('/users/suggest', {prePopulate: assignUserJson}); // doesn't work
And this works:
$('#assignTask').tokenInput('/users/suggest', {prePopulate: [{"id":"1","name":"Andrew"},{"id":"3","name":"John"}]}); // works
Why is that? Shouldn’t I be able to get the value from a hidden input field and pass it to the tokenInput function?
In your first method,
assignUserJsonis a string whereas in the second method, it is an array object. Objectifying the first one should work: