一个插件
jQuery.extend({ toJSON: function(object) { var type = typeof object; if ('object' == type) { if(object){ if (Array == object.constructor) type = 'array'; else if (RegExp == object.constructor) type = 'regexp'; else type = 'object'; } } switch (type) { case 'undefined': case 'unknown': return; break; case 'function': case 'boolean': case 'regexp': return object.toString(); break; case 'number': return isFinite(object) ? object.toString() : 'null'; break; case 'string': return '\'' + object.replace(/(\\|\")/g,"\\$1").replace(/\n|\r|\t/g,function() { var a = arguments[0]; return (a == '\n') ? '\\n': (a == '\r') ? '\\r': (a == '\t') ? '\\t': "" }) + '\''; break; case 'object': if (object === null) return 'null'; var results = []; for (var property in object) { var value = jQuery.toJSON(object[property]); if (value !== undefined) results.push(jQuery.toJSON(property) + ':' + value); } return '{' + results.join(',') + '}'; break; case 'array': var results = []; for (var i = 0; i < object.length; i++) { var value = jQuery.toJSON(object[i]); if (value !== undefined) results.push(value); } return '[' + results.join(',') + ']'; break; } } });
/** * 针对某一用户保存权限 * 1,2,3,4,5 */ savePrivilege: function(){ var checkedNodes = privilege.pFunction.privilegeTree.zTree.getCheckedNodes(true);//所有选择的权限 var mids = ""; for(var i=0;i<checkedNodes.length;i++){ if(i<checkedNodes.length-1){ mids = mids+checkedNodes[i].mid+","; }else{ mids = mids+checkedNodes[i].mid; } } var parameter = { uid:privilege.data.user.uid,mids:mids,checkedNodes //mids是一样的 }; $.post("privilegeAction_savePrivilege.action",parameter,function(data){ }); },原文链接:https://www.f2er.com/ajax/165931.html