如何在select2中更改语言

时间:2017-12-11 11:54:52

标签: javascript jquery jquery-select2

我在v4.0.3中使用select2

我想将默认语言从英语更改为西班牙语。查看国际化部分中的文档,但如上所述,它对我没有用。

我很关注您的评论附件

$("#multisearch").select2({
		     	language: "es",
		     	closeOnSelect: false,
		     	placeholder: "Comienza tu búsqueda",
		  		data: [
		  			{ 
		  				id: 0, 
		  				text: 'Linea 1',
	          			children: 
	          			[{
	                		id: 1,
	                		text: 'San Pablo'
	             		},
	             		{
	                		id: 2,
	                		text: 'Pajaritos'
	               
	             		},
	             		{
	             			id: 3,
	             			text: 'Las Rejas'
	             		},
	             		{
	             			id: 4,
	             			text: 'Ecuador'
	             		}]
	             	},
	             	{ 
		  				id: 5, 
		  				text: 'Linea 2',
	          			children: 
	          			[{
	                		id: 6,
	                		text: 'La Cisterna'
	             		},
	             		{
	                		id: 7,
	                		text: 'El Parrón'
	               
	             		},
	             		{
	             			id: 8,
	             			text: 'Lo Ovalle'
	             		},
	             		{
	             			id: 9,
	             			text: 'Ciudad del niño'
	             		},
	             		{
	             			id: 10,
	             			text: 'Pajaritos'
	             		}
	             		]
	             	},
	          		{ id: 1, text: 'prueba' }, 
		  		]});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
	<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
	<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>


<select multiple id="multisearch" style="width:500px">
</select>

我会很专心,非常感谢你

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
$("#multisearch").select2({ language: "es", closeOnSelect: false, placeholder: "Comienza tu búsqueda", data: [ { id: 0, text: 'Linea 1', children: [{ id: 1, text: 'San Pablo' }, { id: 2, text: 'Pajaritos' }, { id: 3, text: 'Las Rejas' }, { id: 4, text: 'Ecuador' }] }, { id: 5, text: 'Linea 2', children: [{ id: 6, text: 'La Cisterna' }, { id: 7, text: 'El Parrón' }, { id: 8, text: 'Lo Ovalle' }, { id: 9, text: 'Ciudad del niño' }, { id: 10, text: 'Pajaritos' } ] }, { id: 1, text: 'prueba' }, ]});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>


<select multiple id="multisearch" style="width:500px">
</select>
&#13;
&#13;
&#13;