Javascript 选择2添加其他参数以选择选项
我需要为从ajax数据中选择2生成的Javascript 选择2添加其他参数以选择选项,javascript,select2,Javascript,Select2,我需要为从ajax数据中选择2生成的标记提供额外的参数 select2的我的ajax参数(咖啡): 结果数据结构: [{id: 1, text: 'one', price: 100, weight: 10}, {id: w, text: 'two', price: 200, weight: 12}] 默认情况下,选择2仅提供id和text参数,然后选择如下所示: <select> <option value="10" selected="selected">one
标记提供额外的参数
select2的我的ajax参数(咖啡):
结果数据结构:
[{id: 1, text: 'one', price: 100, weight: 10},
{id: w, text: 'two', price: 200, weight: 12}]
默认情况下,选择2仅提供id
和text
参数,然后选择如下所示:
<select>
<option value="10" selected="selected">one</option>
<option value="11" selected="selected">one</option>
</select>
如果无法使用
标记,则如果我将
放入
中,并向
添加参数(如果JQuery是一个选项),则这将是正常的:
$('#optionTag').attr('my-awesome-attr','12'); //this is if you give the option tag an idea of 'optionTag'
我可以通过
$('select')访问我的其他参数。select2('data')
并获取包含所有参数的对象了解数据-*
属性。我从未使用过select2或CoffeeScript,恐怕:(
<option value="11" selected="selected" price="12" weight="100">one</option>
$('#optionTag').attr('my-awesome-attr','12'); //this is if you give the option tag an idea of 'optionTag'