Turn option values into json format

0

Hello, I have the following question, I am dynamically creating the selected, for each option of it selected, it contains two values: DominioID and PaiID, but I need to pass both at the same time but I am not able to transform this value into json format. p>

My option is this way:

  $('#telaValoresDominio')
            .append('<option class="getValueDominio" value="DominioID:' + value["id"] + ',PaiID:' + value["parent"] +'">' + value["text"] + '</option>');

I'm capturing the values as follows:

 var dominArray = [];
    var strUser = $('#telaValoresDominio').val();
    var x = document.getElementById("telaValoresDominio").value;


    $("#telaValoresDominio option").each(function () {
        // Add $(this).val() to your list
        dominArray.push($(this).val().split(","));

        //console.log($(this).val());
    });

But it turns this value into an array of 2d, I made a conversion to array of 1d, like this:

  function get1DArray(arr) {
        return arr.join().split(",");
    }
    var jsonSerialized = get1DArray(dominArray);

Only when I send this to my web api it send as "dominioID:1","PaiID:2" , I want to transform it into a json format, like this: {"DominoID":"1","PaiID":"2"}

    
asked by anonymous 15.12.2018 / 13:56

0 answers