I have an arrangement defined in vue productos:[]
I add elements with this function: (vue code)
var appmeta = new Vue({
//
el: '#v_meta',
created: function(){
this.getMetas();
},
data:{
metas:[],
pagination:{
'total' : 0,
'current_page' : 0,
'per_page' : 0,
'last_page' : 0,
'from' : 0,
'to' : 0
},
newMeta:{META_intId: '', META_varSubMeta: '', META_varDenominacion: '', META_intYear: ''},
fillMeta:{META_intId: '', META_varSubMeta: '', META_varDenominacion: '', META_intYear: ''},
personaSeleccionada:'',
newContrato:{CONT_intTiempoContrato:'',CONT_varProfesion:'',CONT_varGradoAcademico:'',CONT_douMontoTotal:'',CONT_intArmadas:'',META_intId:'',PERS_varDNI:'',CONT_datInicio:'',CONT_datFin:'',productos:[]},
},
methods:{
eltoProducto: function(){
document.getElementById('tablaProductos').style.visibility="visible";
var table = document.getElementById("tablaProductos");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var ncantidad= document.getElementById('Cantidad').value;
var ntexto=document.getElementById('Productos').value;
cell1.innerHTML = ncantidad;
cell2.innerHTML = ntexto;
cell3.innerHTML='<a href="# " class="btn btn-success btn-sm" onclick="delRow(this)">btn</a>';
var elto={cantidad:ncantidad,denominacion:ntexto};
this.newContrato.productos.push(elto);
document.getElementById('Cantidad').value=0;
document.getElementById('Productos').value="";
},
}
Now I have a view:
<table class="table table-hover table-striped table-bordered" id="tablaProductos" style="visibility: hidden;" >
<thead>
<th width="10px">Cantidad</th>
<th>Denominación</th>
<th>Accion</th>
</thead>
<tbody>
</tbody>
</table>
where I declare a:
@section('scripts')
<script type="text/javascript">
delRow = function(rr){
var i = rr.parentNode.parentNode.rowIndex;
document.getElementById("tablaProductos").deleteRow(i);
this.newContrato.productos.splice(i,1);
};
</script>
@endsection
What I want is to remove the elements added in the productos:[]
array and also delete the same element in the tablaProductos
table when I press the corresponding row button 'btn'.
So far I can delete the elements of the view, but not the variable newContract.products