Domanda

Sto usando Extjs con i binari ... Sto cercando di eliminare i record selezionati in Grid tramite "Colonna di controllo" ... Non ho idea di come posso gestire "Array" dei record selezionati di Grid tramite rotaieController ... plzz guidarmi ... Il codice sul pulsante Elimina è il seguente:

var sm = prodgrid.getSelectionModel();
delbtn.on("click", function () {
    var sel = sm.getSelections();
    Ext.Ajax.request({
        url: 'products/delete',
        //   method:'DELETE',
        params: {
            'prodid': sel
        }

    });

});
.

Come posso isolare attraverso la matrice "sel" nel mio controller dei binari ??Aiuto PLTC

È stato utile?

Soluzione

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);
});

Altri suggerimenti

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)
    }

}); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top