[英]select 2 add additional parameters to select options
I need additional parameters for <option></option>
tag that generates by select2 from ajax data. 我需要来自ajax数据的select2生成的
<option></option>
标记的附加参数。
My ajax params for select2(coffee): 我的ajax params for select2(咖啡):
ajax:
url: '/moysklad_warehouse_items/find_warehouse_item'
dataType: 'json'
delay: 500
data: (query) ->
{ q: query.term }
processResults: (data) ->
{ results: data }
Resulted data structure: 结果数据结构:
[{id: 1, text: 'one', price: 100, weight: 10},
{id: w, text: 'two', price: 200, weight: 12}]
By default select2 provide only id
and text
parameters and select looks like this: 默认情况下,select2仅提供
id
和text
参数,并选择如下所示:
<select>
<option value="10" selected="selected">one</option>
<option value="11" selected="selected">one</option>
</select>
I want to add additional data(price and weight), like, that parameters take part in calculations and only text
tag if insufficiently 我想添加额外的数据(价格和重量),比如,参数参与计算,如果不充分,则只添加
text
标签
<option value="11" selected="selected" price="12" weight="100">one</option>
If its impossible for <option></option>
tag, it would be normal if I put, for example, <span></span>
inside <option>
and add parameters to <span>
如果
<option></option>
标签不可能,那么如果我将<span></span>
放在<option>
并将参数添加到<span>
我可以通过$('select').select2('data')
访问我的附加参数,并获取所有参数的对象
如果JQuery是一个选项:
$('#optionTag').attr('my-awesome-attr','12'); //this is if you give the option tag an idea of 'optionTag'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.