1.去除对象中为空的属性
function handleValue(data) {
for ( var key in data ){
if ( data[key] === '' || data[key] === undefined ){
delete data[key]
}
}
return data;
}
2.json转url参数
function parseParams(data) {
try {
var tempArr = [];
for (var i in data) {
var key = encodeURIComponent(i);
var value = encodeURIComponent(data[i]);
tempArr.push(key + '=' + value);
}
var urlParamsStr = tempArr.join('&');
return urlParamsStr;
} catch (err) {
return '';
}
}