...
|
...
|
@@ -306,23 +306,44 @@ var util = { |
|
|
}
|
|
|
return obj;
|
|
|
},
|
|
|
__ArrayToObj:function(data){
|
|
|
var result={};
|
|
|
if($.isArray(data)){
|
|
|
data.forEach(function(item,index){
|
|
|
result[index]=item;
|
|
|
});
|
|
|
}else if(typeof data=="string"){
|
|
|
result=data;
|
|
|
}
|
|
|
else{
|
|
|
for(var i in data){
|
|
|
if(data.hasOwnProperty(i)){
|
|
|
result[i]=util.__ArrayToObj(data[i])
|
|
|
__ArrayToObj:function(data){
|
|
|
var result={};
|
|
|
if($.isArray(data)){
|
|
|
data.forEach(function(item,index){
|
|
|
result[index]=item;
|
|
|
});
|
|
|
}else if(typeof data=="string"){
|
|
|
result=data;
|
|
|
}
|
|
|
else{
|
|
|
for(var i in data){
|
|
|
if(data.hasOwnProperty(i)){
|
|
|
result[i]=util.__ArrayToObj(data[i])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
},
|
|
|
__ObjToArray:function(data){
|
|
|
var result={};
|
|
|
if([].toString.call(data)=="[object Object]"){
|
|
|
for(var name in data){
|
|
|
if(data.hasOwnProperty(name)&&/^\d+$/.test(name)){
|
|
|
result=$.isArray(result)?result:[];
|
|
|
result.push(util.__ObjToArray(data[name]));
|
|
|
}else{
|
|
|
result[name]=util.__ObjToArray(data[name]);
|
|
|
}
|
|
|
}
|
|
|
data=result;
|
|
|
}else if(typeof data=="string"){
|
|
|
result=data;
|
|
|
}else{
|
|
|
/*基本不会被运行到,需要优化*/
|
|
|
result=$.isArray(result)?result:[];
|
|
|
result=data;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
module.exports = util; |
|
|
\ No newline at end of file |
...
|
...
|
|