开发者

extjs checkbox grid delete rails

i am using ExtJS with Rails...I am trying to delete records selected in grid through "Checkbox column"...i dnt have any idea as to how can i handle "Array" of selected records of grid through rails controller...plzz guide me... the code on delete button is as follows :

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

    });

});

How can i itera开发者_如何学Gote through "sel" array in my Rails controller?? plzz help


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


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

}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜