Extjs CheckBox Grid Eliminar rieles
-
14-11-2019 - |
Pregunta
Estoy usando extjs con rieles ... Estoy tratando de eliminar los registros seleccionados en la cuadrícula a través de "columna de la casilla de verificación" ... No tengo una idea de cómo puedo manejar la "matriz" de registros seleccionados de cuadrícula a través de rielesControlador ... PLZZ Guide me ... El botón Código en Eliminar es el siguiente:
var sm = prodgrid.getSelectionModel();
delbtn.on("click", function () {
var sel = sm.getSelections();
Ext.Ajax.request({
url: 'products/delete',
// method:'DELETE',
params: {
'prodid': sel
}
});
});
¿Cómo puedo iterar a través de la matriz "SEL" en mi controlador de rieles?PLZZ HELP
Solución
use Ext.each
to iterate an array :
var sm = prodgrid.getSelectionModel();
delbtn.on("click", function () {
var sel = sm.getSelections();
Ext.each(sel,function(data){
/// your stuff
Ext.Ajax.request({
url: 'products/delete',
// method:'DELETE',
params: {
'prodid': data.id // the parameter
}
});
///// end
},this);
});
Otros consejos
You cannot pass arrays into Rails controller directly. This article should help you in understanding parameter passing into rails controllers.
That said, you need to convert the array into a string. You can use a function similar to this for converting the array to string:
function array_params(arry) {
var paramvar = "";
arry.each(function(s){
paramvar = paramvar.concat("arr[]=",s,"&");});
paramvar = paramvar.replace(/&$/,"");
return paramvar;
}
and finally call:
Ext.Ajax.request({
url: 'products/delete',
// method:'DELETE',
params: {
'prodid': array_params(sel)
}
});