Cloned Select2 is not responding

前端 未结 13 2344
长发绾君心
长发绾君心 2020-11-29 03:51

I am trying to clone a row which contains select2 tool ,when i clone that row using jQuery the cloned select2 is not responding.In image given below first select2 which is o

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 04:36

    And one more solution:

    function add_column(copy, paste) {
        $("." + copy + ":first").clone().appendTo("." + paste);
        $("." + paste + " tr:last input").val('');
        $("." + paste + " tr:last select").val('');
        // and etc...
    
    		// Initialize
    		$("." + paste + " tr:last select").select2({
    		    language: {
    		        inputTooShort: function() {
    		        return 'Prašome įvesti bent vieną raidę paieškai';
    		    }},
    		    ajax: {
    		        url: base_url+"fuel/Fuel/getWorkersSelect",
    		        type: 'POST',
    		        dataType: 'json',
    		        delay: 250,
    		        data: function (params) {
    		            return {
    		                q: params.term, // search term
    		                page: params.page
    		            };
    		        },
    		        processResults: function (data, params) {
    
    		            // parse the results into the format expected by Select2
    		            // since we are using custom formatting functions we do not need to
    		            // alter the remote JSON data, except to indicate that infinite
    		            // scrolling can be used
    		            params.page = params.page || 1;
    
    		            return {
    		                results: data,
    		                pagination: {
    		                    more: (params.page * 30) < data.total_count
    		                }
    		            };
    		        },
    		        cache: true
    		    },
    		    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
    		    minimumInputLength: 1,
    		    templateResult: formatRepo, // omitted for brevity, see the source of this page
    		    templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
    		});
    
        $("." + paste + " tr:last select").last().next().next().remove();
    
    }
    
    function remove_column(e, paste) {
        var how = $("." + paste + " tr").length;
        if (how >= 2) {
            $(e).parent().parent().remove();
        } else {
            $("." + paste + " input").val('');
            $("." + paste + " select").val('');
            // and etc...
        }
    }
    Mašina Išduota Grąžinta Vairuotojas Neaktualus Perdavimo aktas Veiksmai
    haha  

提交回复
热议问题