js判断是对象还是集合

/*============================================
函数功能:对返回数据中的列表数据进行非空处理
=============================================*/
function formatResponseData(response, str)
{
    // 判断入参是对象还是集合, 然后不同的处理
    var cxlb = response.toString() == "[object Object]" ?  response.cxlb : toString.apply(response) == "[object Array]" ? response : [];
    str = str == undefined ? "--" : str;

    for(var i = 0 , len = cxlb.length; i < len; i++)
    {
        for(var j = 0, len2 = cxlb[i].length; j < len2; j++)
        {
            cxlb[i][j] = cxlb[i][j] == undefined || cxlb[i][j] == null || cxlb[i][j].trim() == "" ? str : cxlb[i][j];
        }
    }
}

 

posted @ 2016-06-11 11:06  无天666  阅读(2687)  评论(0编辑  收藏  举报