-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
数组中有对象avalon.param转后对象丢失 #10
Comments
我看一看 |
搞定 function isDate(a) {
return Object.prototype.toString.call(a) === "[object Date]"
}
if (!Date.prototype.toISOString) {
(function() {
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
Date.prototype.toISOString = function() {
return this.getUTCFullYear() +
'-' + pad(this.getUTCMonth() + 1) +
'-' + pad(this.getUTCDate()) +
'T' + pad(this.getUTCHours()) +
':' + pad(this.getUTCMinutes()) +
':' + pad(this.getUTCSeconds()) +
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
'Z';
};
}());
}
function paramInner(json, prefix, buffer) {
prefix = prefix || ""
for (var key in json) {
if (json.hasOwnProperty(key)) {
var val = json[key]
var name = prefix ? prefix + encode("[" + key + "]") : encode(key)
if (isDate(val)) {
buffer.push(name + "=" + val.toISOString())
} else if (isValidParamValue(val)) {//如果是简单数据类型
buffer.push(name + "=" + encode(val))
} else if (Array.isArray(val) || avalon.isPlainObject(val)) {
avalon.each(val, function(subKey, subVal) {
if (isValidParamValue(subVal)) {
buffer.push(name + encode("[" + subKey + "]") + "=" + encode(subVal))
} else if (Array.isArray(val) || avalon.isPlainObject(val)) {
paramInner(subVal, name + encode("[" + subKey + "]"), buffer)
}
})
}
}
}
}
function isValidParamValue(val) {
var t = typeof val; // 值只能为 null, undefined, number, string, boolean
return val == null || (t !== 'object' && t !== 'function')
}
//将一个对象转换为字符串
avalon. param = function(json) {
if (!avalon.isPlainObject(json)) {
return "";
}
var buffer = []
paramInner(json, "", buffer)
return buffer.join("&").replace(r20, "+")
} |
真迅速,3q哈~~ 发件人: 司徒正美 [mailto:notifications@github.com] — |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以上是avalon的测试
以上是jq的。。
丢了数据了~~
The text was updated successfully, but these errors were encountered: