Extra data with initial value (ajax select2)

281 views
Skip to first unread message

Chris

unread,
Feb 8, 2017, 1:48:34 PM2/8/17
to select2
I have an ajax select2 box that works well. When an ajax query is made, the server returns some extra data. eg.

[
{id: 5, text: "My Text Here", extra_field: "Extra Value"}
]


When I want to set an initial value, how do I get that extra_field data in there? A regular option tag.
eg.
<select>
<option value="5" selected>My Text Here</option>
</select>

works for the value/text, but I can't figure out how to get the extra_field in there so I can reference it later. I'm hoping there's an easy way to do this (eg. data tags, or somehow passing in a json hash as the selected value instead of option tags).

Thanks for any help/advice!

Chris

unread,
Feb 8, 2017, 5:43:33 PM2/8/17
to select2
It seems one way is to have two arrays - one that you pass in as the 'data' argument when initializing the select2, and then the other you can use to set the selected value (as per this answer: http://stackoverflow.com/a/38141552 ).

Electric Bikes Backlinks

unread,
Jan 11, 2026, 7:36:45 AMJan 11
to select2
When setting an initial value in Select2, you can include extra data like 'extra_field' by passing a data object instead of just plain option tags. This way, the additional data is stored with the selected item and can be accessed later, making technology makes it easier to work with custom data fields in your Select2 dropdown.

Amz Doc

unread,
Jul 14, 2026, 7:56:29 PM (10 days ago) Jul 14
to select2
  Keeping online discussions easy to follow often comes down to sharing tools and resources that solve specific needs without adding clutter. For people managing busy routines and looking for practical ways to handle cleaning tasks, options like  https://duckvacuum.org/   can be a useful reference point. It fits naturally into conversations where users value simple solutions and helpful recommendations from real experiences.  

Aliyan

unread,
Jul 14, 2026, 7:56:44 PM (10 days ago) Jul 14
to select2
 Working with structured data fields in tools like Select2 often comes down to keeping the right information connected while maintaining a clean user experience. The same idea applies when choosing everyday pieces like a bandier sweatshirt, where comfort and practical design details help make a simple choice easier. Small details in both coding and clothing can improve how people interact with and use what they choose.  
On Sunday, January 11, 2026 at 5:36:45 PM UTC+5 Electric Bikes Backlinks wrote:

Blu Fx

unread,
Jul 14, 2026, 7:56:57 PM (10 days ago) Jul 14
to select2
  Keeping a kitchen workflow organized often comes down to having simple tools that make routine tasks easier. A good Chopper can help with everyday prep when you need to handle ingredients quickly without adding extra effort. Small improvements like this can make daily cooking tasks smoother and more convenient.  

anderson ashtonwill

unread,
Jul 14, 2026, 7:57:10 PM (10 days ago) Jul 14
to select2

Organizing tools properly can make a workspace much easier to manage, especially when small parts and equipment need to stay accessible. Drawers are a useful addition for keeping items separated and reducing clutter during regular tasks or projects. A well arranged storage setup helps save time and keeps everything in its place when you need it.


On Sunday, 11 January 2026 at 17:36:45 UTC+5 Electric Bikes Backlinks wrote:

caserne1830

unread,
Jul 14, 2026, 7:57:23 PM (10 days ago) Jul 14
to select2
  Having a reliable power source can make a big difference during travel, outdoor activities, or unexpected outages. An inverter helps convert power when needed, making it easier to run small devices without relying on a traditional outlet. Options like the Halo Bolt ACDC can be useful for people looking for portable backup power solutions in different situations.  

On Sunday, 11 January 2026 at 17:36:45 UTC+5 Electric Bikes Backlinks wrote:
Reply all
Reply to author
Forward
0 new messages