Name of the dynamic attribute in Post Jquery

0

How can I use the variable data type as the title / name of the attribute that will be passed in POST?

The type is dynamic because it is actually the name of the column in the database.

$('body').on('click', '.setCompany', function(e){
        var type = $('.modal.in').attr('data-type')
        var id = $(this).attr('id')

        $.post("/admin/purchase_orders_groups/8",
            { ${type}: id, _method: 'PUT' }
        )
})
    
asked by anonymous 16.03.2018 / 14:30

1 answer

1

So I think it solves your problem:

var type = 'AlgumaCoisa';
var id   = 'AlgumValor';

var x = { ['${type }']: id, _method: 'PUT' };
console.log(x);

This works on Ecmascript 6

    
16.03.2018 / 15:31