how to init select2 tags with an array of objects

4,001 views
Skip to first unread message

maku

unread,
Jul 25, 2012, 12:13:57 PM7/25/12
to sel...@googlegroups.com
I would like to use select2 with angularjs and I have data in the form of 

e.g. 
tags=[{"id": "01","text": "Perl"},{"id": "02","text": "Java"},{"id": "03","text": "JavaScript"},{"id": "04","text": "Scala"}];

setting tags in this form works.

But setting data in this form doesn't work e.g [{"id": "02","text": "Java"}];
Because of data binding issues (angular-ui) -> is it possible to set the 'data' in this form ?? 

BTW,It should also possible to create new tags... (like standard tag behaviour)

Now I'm only able to use set the preselected tags in the form of  ["01","02"] via 'data'

Can anybody of you give me a hint???

TIA

Igor Vaynberg

unread,
Jul 25, 2012, 3:47:01 PM7/25/12
to sel...@googlegroups.com
tags are objects where id==text.

what you want is to use the local helper option to specify an array of
objects which will allow you to use the data() func in the format you
want.

to create new items you need to specify createSearchChoice() function,
there are examples on the demo site.

-igor
> --
> You received this message because you are subscribed to the Google Groups
> "select2" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/select2/-/tAhsWLxbVZoJ.
> To post to this group, send email to sel...@googlegroups.com.
> To unsubscribe from this group, send email to
> select2+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/select2?hl=en.

maku

unread,
Jul 26, 2012, 4:00:47 AM7/26/12
to sel...@googlegroups.com
I tried but I have no idea how to set preselection.


TIA

Igor Vaynberg

unread,
Jul 26, 2012, 9:05:22 AM7/26/12
to sel...@googlegroups.com
http://jsfiddle.net/5HZB3/7/

-igor
>> > select2+u...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/select2?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "select2" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/select2/-/Ng3MWV6KNjsJ.
>
> To post to this group, send email to sel...@googlegroups.com.
> To unsubscribe from this group, send email to
> select2+u...@googlegroups.com.

maku

unread,
Jul 27, 2012, 9:40:03 AM7/27/12
to sel...@googlegroups.com
Thank you very much, this works....
martin
>> > For more options, visit this group at
>> > http://groups.google.com/group/select2?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "select2" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/select2/-/Ng3MWV6KNjsJ.
>
> To post to this group, send email to sel...@googlegroups.com.
> To unsubscribe from this group, send email to
Reply all
Reply to author
Forward
0 new messages