loading array data

Select2 provides some shortcuts that make it easy to access local data stored in an array instead of having to write a query function mentioned in the eg above.

eg below inlines the data by specifying an array in the data element. items in such an array must have id & text keys.

 

 

 

 

 

 

 

 

eg code:

  1. $(“#e10”).select2({
  2. data:[{id:0,text:’enhancement’},{id:1,text:’bug’},{id:2,text:’duplicate’},{id:3,text:’invalid’},{id:4,text:’wontfix’}]
  3. });
  4. var data=[{id:0,tag:’enhancement’},{id:1,tag:’bug’},{id:2,tag:’duplicate’},{id:3,tag:’invalid’},{id:4,tag:’wontfix’}];
  5. function format(item) { return item.tag; };
  6. $(“#e10_2”).select2({
  7. data:{ results: data, text: ‘tag’ },
  8. formatSelection: format,
  9. formatResult: format
  10. });
  11. $(“#e10_3”).select2({
  12. data:{ results: data, text: function(item) { console.log(‘called with’, item); return item.tag; } },
  13. formatSelection: format,
  14. formatResult: format
  15. });

51 responses »

  1. l-tyrosine says:

    You have observed very interesting points! ps nice site.

  2. picamilon says:

    Very interesting information!Perfect just what I was searching for!

  3. This writing has inspired me to carry on focusing on my own blog

  4. epa says:

    I like your useful writing. super contribution. I hope you release many. I will carry on reading

  5. SJW says:

    Very interesting information!Perfect just what I was searching for!

  6. nootropic says:

    Rattling wonderful info can be found on this web site.

  7. jailbreak says:

    I view something genuinely interesting about your site so I saved to favorites .

  8. jailbreak says:

    I adored your rich article. topnotch contribution. I hope you release many. I will continue reading

  9. salutations from over the sea. Great article I must return for more.

  10. senile says:

    Rattling superb info can be found on this web blog.

  11. salutations from over the world. detailed post I shall return for more.

  12. salutations from across the ocean. interesting post I will return for more.

  13. click this says:

    I consider something really interesting about your web blog so I saved to bookmarks .

  14. Very interesting info!Perfect just what I was looking for!

  15. I view something genuinely interesting about your web blog so I saved to fav.

  16. vitamin says:

    Greeting from over the sea. Great post I will return for more.

  17. l-tyrosine says:

    Greeting from over the ocean. Great blog I will return for more.

  18. incontinence says:

    You have noted very interesting points! ps decent website.

  19. notropics says:

    Greeting from over the world. informative post I shall return for more.

  20. picamilon says:

    Cheers, I just stopped by to visit your website and thought I’d say thank you.

  21. salutations from across the sea. excellent post I must return for more.

  22. nootropics says:

    Hello, i believe that i noticed you visited my site so i came to “return the choose”.I am trying to to find issues to enhance my site!I assume its ok to use some of your concepts!!

  23. nootropics says:

    This publication has inspired me to carry on focusing on my own blog

  24. Hey there would you mind letting me know which web host you’re working with? I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most. Can you recommend a good hosting provider at a reasonable price? Many thanks, I appreciate it!

  25. Very interesting information!Perfect just what I was searching for!

  26. Very interesting info!Perfect just what I was searching for!

  27. I pondered posting this pingback great feature

  28. I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more frequently. How frequently you update your website?

  29. Where I’m from we don’t get any of this kind of article. Got to look around the entire world for such relevant pieces. I appreciate your energy. We want more!

  30. fitness says:

    glad to be one of several visitants on this awing internet site : D.

  31. fitness says:

    When I initially commented I clicked the -Notify me when new feedback are added- checkbox and now every time a remark is added I get four emails with the same comment. Is there any method you’ll be able to remove me from that service? Thanks!

  32. fitness says:

    I love the efforts you have put in this, thanks for all the great blog posts.

  33. This excellent website truly has all of the info I wanted concerning this subject and didn’t know who to ask.

  34. I just want to tell you that I’m very new to weblog and honestly liked this internet internet site. More than likely I’m preparing to bookmark your weblog post . You undoubtedly come with exceptional articles and reviews. Bless you for sharing your web internet site.

  35. IM Forum says:

    I really enjoy looking through on this site, it has fantastic content. “One should die proudly when it is no longer possible to live proudly.” by Friedrich Wilhelm Nietzsche.

  36. Some truly fantastic content on this site, thankyou for contribution.

  37. Thank for sharing your childhood story.

  38. mind matter says:

    Very great info can be found on web site.

  39. So … the NCAA controls the rules by which a conference needs to meet requirements to hold a conference championship, but they have no jurisdiction over the bowls and national championship? Or interest in doing so?

  40. Valeri Hugar says:

    Wonderful post! I?m just starting out in community management/marketing media and trying to learn how to do it effectively – resources like this article are incredibly beneficial. As our company is based inside the US, it?s all a bit new to us. The example above is something that I worry about as nicely, how to show your personal genuine enthusiasm and share the fact that your product is beneficial in that case

  41. I’m not sure why but this web site is loading incredibly slow for me. Is anyone else having this issue or is it a issue on my end? I’ll check back later on and see if the problem still exists.

  42. Wohh just what I was looking for, thanks for putting up.

  43. Extremely interesting topic , regards for putting up.

  44. Greetings! Quick question that’s completely off topic. Do you know how to make your web site mobile friendly? My weblog looks weird when viewing from my iphone. I’m trying to discover a template or plugin that may be able to fix this dilemma. If you have any recommendations, please share. Appreciate it!

  45. Rosena Rath says:

    Useful information shared. I’m quite pleased to read this article. thanks for giving us good information. Wonderful walk-through. I appreciate this post.

  46. I quite like looking through an article that can make people think. Also, many thanks for allowing me to comment.

  47. This site really has all of the information I needed concerning this subject and didn’t know who to ask.

  48. Beau Kuhens says:

    Sweet site, super pattern , really clean and use friendly .

As salam. Hi. Leave a Comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s