Selectize - Clone 3 select с динамическим значением c - PullRequest
0 голосов
/ 24 марта 2020

Я использую selectize. js, и я хочу клонировать строку с помощью 3 select:

  1. Выбрать по имени сотрудника (можно добавить нового)
  2. Позиция (stati c value)
  3. Умения (это динамические c, потому что они изменяются в соответствии с предыдущими выборами)

Когда я клонирую строку, третий строка (опция умений) в клонированной строке удаляется, и ее значение отсутствует, поскольку она генерируется динамически из предыдущего выбора (комбинация select1 + selec2).

Мой код:

cloneItem: function (e) {
    e.preventDefault()
    let elementDiv = $('div[id^="worker"]:last')
    let num = parseInt( elementDiv.prop('id').match(/\d+/g), 10 ) +1

    $('.select').each(function(){ // do this for every select with the 'combobox' class
        if ($(this)[0].selectize) { // requires [0] to select the proper object
            var value = $(this).val(); // store the current value of the select/input
            $(this)[0].selectize.destroy(); // destroys selectize()
            $(this).val(value);  // set back the value of the select/input
        }
    })

    $('.select1').each(function(){ // do this for every select with the 'combobox' class
        if ($(this)[0].selectize) { // requires [0] to select the proper object
            var value = $(this).val(); // store the current value of the select/input
            $(this)[0].selectize.destroy(); // destroys selectize()
            $(this).val(value);  // set back the value of the select/input
        }
    })

    $('.select2').each(function(){ // do this for every select with the 'combobox' class
        if ($(this)[0].selectize) { // requires [0] to select the proper object
            var value = $(this).val(); // store the current value of the select/input
            $(this)[0].selectize.destroy(); // destroys selectize()
            $(this).val(value);  // set back the value of the select/input
        }
    })

    $('#worker1')
    .clone() // copy
    .prop('id', 'worker' + num )
    .insertAfter('.clone_item:last'); // where		
    
    $('.select, .select2').selectize({
        create: true,
        sortField: 'text'
    })
    $('.select-beast1').selectize()
},
<div class="clone_item" id="worker1">									
    <div class="medium-3">
        <select class="select peoples" name="people">
            {{#each peoples}}
            <option value="{{value}}">{{label}}</option>
            {{/each}}
        </select>
    </div>
    <div class="medium-3">
        <select class="select1 positions" name="position" disabled>
            {{#each positions}}
            <option value="{{value}}">{{label}}</option>
            {{/each}}
        </select>
    </div>
    <div class="medium-4">										
        <select class="select2 skills" name="skill" />								
    </div>
</div>

Любая идея, чтобы решить это?

...