First select2 value is not shown when using i18next

2

I'm doing internationalization with lib i18next, everything happens right, it translates puts the values inside the select2 , however the first value is not shown in any way, even though I open select2 and clicking on the first item . Anyone have an idea of what might be happening?

HTML:

<html>
<head><title>Select2</title></head>
<body>
   <div>
      <label class="col-sm-12 text-white" style="text-align: left;" data-i18n="store.tipo"> </label>
      <div class="col-sm-12">
         <select id="selectTipo" class="form-control"></select>
         <br/>
         <br/>
      </div>
   </div>
   <script src="~/lib/jquery.js" type="text/javascript"></script>
   <script src="~/lib/select2.js" type="text/javascript"></script>
   <script src="~/js/arquivo.js" type="text/javascript"></script>
   <script type="text/javascript">
      $(document).ready(function(){
         GetTipo();
      })
   </script>
</body>
</html>

Javascript: (.js file)

function GetTipo(){
var $selectTipo = $('#selectTipo');

$selectTipo.append($('<option data-i18n="store.comboTipos.todos">', { value: "0", text: $(this).data('data-i18n')}));
$selectTipo.append($('<option data-i18n="store.comboTipos.painel">', { value: "1", text: $(this).data('data-i18n') }));
$selectTipo.append($('<option data-i18n="store.comboTipos.report">', { value: "2", text: $(this).data('data-i18n') }));
$selectTipo.append($('<option data-i18n="store.comboTipos.notificacao">', { value: "3", text: $(this).data('data-i18n') }));
$selectTipo.append($('<option data-i18n="store.comboTipos.auditoria">', { value: "4", text: $(this).data('data-i18n') }));
$selectTipo.append($('<option data-i18n="store.comboTipos.apresentacao">', { value: "5", text: $(this).data('data-i18n') }));
$selectTipo.val("0").trigger("change");
$selectTipo.select2();
}

IMAGE:

JSFIDDLE:(resolvedlink)

link

    
asked by anonymous 07.10.2015 / 13:15

1 answer

1

I was able to find a way:

As you are working with dynamic content, the library is unable to handle properly.

After setting up the dynamic combo, place these two faces down at the end, just after adding the dynamic fields.

$("#selectTipo").i18n();
$('#selectTipo').select2();
    
07.10.2015 / 16:42