fredeaster
fredeaster

Reputation: 3

Jquery-tokeninput String parameter

Just started using token-input, and i didn't manage to make it work the way I wanted. Let me explain :

I was given a String var in javascript, containing data, like token-input local data:

var str='[{id : 1, name : "ADM" },
{id : 2, name : "JCH" },
{id : 3, name : "CGD" }]';

However, I couldn't give a str as a parameter to tokeninput, like this:

$("#input").tokenInput(str, {preventDuplicates : true});

It gives me what I think is error code 500.

Error probably comes with the quote returned by the str var. Problem is I need to use this var, it's kinda imposed.

Any ideas?

Upvotes: 0

Views: 173

Answers (1)

void
void

Reputation: 36703

What you should do is

$("#input").tokenInput(JSON.parse(str), {preventDuplicates : true});

Upvotes: 1

Related Questions