0
I need to create an array this way:
"M":["02328280006985",{"61","63"},],"NM":["02328280007876",{"62","64"}]}
but it’s coming out that way:
"M":["02328280006985",{"61":[],"62":[],"63":[],"64":[]},{"61":[],"62":[],"63":[],"64":[]}],"NM":["02328280006985",{"61":[],"62":[],"63":[],"64":[]}]}
My code is this:
var var ds_rateio = {};
var teste = {};
$('select[name="insTipoRateio[]"] option:selected').each(function() {
if(typeof(ds_rateio[$(this).val()]) == 'undefined' || typeof(teste[$(this).attr("data-nf")]) == 'undefined'){
ds_rateio[$(this).val()] = [];
teste[$(this).attr("data-nf")] = [];
}
ds_rateio[$(this).val()].push($(this).attr("data-cnpj"));
$.each(ds_rateio, function(key1, value) {
value.push(teste);
});
});
var ds_rateio = JSON.stringify(ds_rateio);
My Html:
<tr>
<td>
<div>
<select class="insTipoRateio" id="insTipoRateio" name="insTipoRateio[]">
<option value="M" data-nf="61"data-cnpj="02328280007876">M</option>
</select>
</div>
</td>
<td>
<div>
<select class="insTipoRateio" id="insTipoRateio" name="insTipoRateio[]">
<option value="NM" data-nf="62"data-cnpj="02328280006985">NM</option>
</select>
</div>
</td>
<td>
<div>
<select class="insTipoRateio" id="insTipoRateio" name="insTipoRateio[]">
<option value="M" data-nf="63"data-cnpj="02328280007876">M</option>
</select>
</div>
</td>
<td>
<div>
<select class="insTipoRateio" id="insTipoRateio" name="insTipoRateio[]">
<option value="NM" data-nf="64"data-cnpj="02328280006985">NM</option>
</select>
</div>
</td>
Anyone can help?
The ideal is to include html also to be able to test directly here on the site. In addition, it is advisable to explain where the numbers come from and the rule to know which ones to catch.
– Isac
Edited Isac. What is needed is to create an array by type (M or NM), each type is another CNPJ array (cnpj1, cnpj2) and each CNPJ is another array with Fiscal Notes (61, 63), (62, 64)
– Eduardo