jqgrid - how to add parameters to extraparam of saveRow in inline editing mode

前端 未结 2 1500
温柔的废话
温柔的废话 2021-01-25 15:25

I have a string:

var str = \"it\'s a beautiful day\";

I am passing this string to the function:

rowSave(id, str);
相关标签:
2条回答
  • 2021-01-25 15:52

    The code can be about the following:

    var rowSave = function(id, str) {
        var strParts = str.split(' '), l = strParts.length, i, obj = {},
            codeStart = 'A'.charCodeAt(0); // 65
    
        for (i = 0; i < l; i++, codeStart++) {
            obj[String.fromCharCode(codeStart)] = strParts[i];
        }
        $("#myjqgrid").jqGrid('saveRow', id, {
            succesfunc: function(response) {
                return true;                
            },                                  
            url: "server.aspx",
            mtype: "GET",
            extraparam: obj
        });
    }
    

    First the obj will be filled as {A: "it\'s", B: "a", C: "beautiful", D: "day"} and then it will be used as the value of extraparam.

    0 讨论(0)
  • 2021-01-25 15:55

    You can define a function similar to the following to build up the extra parameter object:

    function encodeStr(str){
        var s = str.split(' '), i, result = {};
    
        for (i = 0; i < s.length; i++){
            result['param' + i] = s[i];
        }
    
        return (result);
    }
    

    jQuery.ajax is used internally by jqGrid and may ensure proper serialization. If you run into problems, use encodeURIComponent to encode each parameter.

    Anyway, then just call into this object when you specify your parameters:

    "extraparam": encodeStr(str)
    
    0 讨论(0)
提交回复
热议问题