2013-07-02 43 views
1

我试图从转换为select2的输入的html5数据属性中读取一个集合来创建标签。

这是工作时,我有一个输入:

$(".tags").select2(
    width: '220px' 
    tags: $(".tags").data('collection') 
) 

但我会喜欢使用元素本身的数据做更安全,我想这一点:

$(".tags").select2(
    width: '220px' 
    tags: $(this).data('collection') 
) 

但失败并显示错误:

Uncaught query function not defined for Select2 investigador_aplicaciones 

是否知道是否可以使用具有特定选择的元素本身像$(这个)?

$(".tags").each(function(){ 
    var $this = $(this); 
    $this.select2({ 
    width: '220px', 
    tags: $this.data('collection') 
    }); 
}); 

因为您的通话this的选择并不代表元素中:

+0

什么是select2? – 2013-07-03 12:35:39

+0

@ user182669 - [Select2](http://ivaynberg.github.io/select2/)是一个增强