Add support for to flatten array
This commit is contained in:
parent
740f31092c
commit
527c506579
|
@ -22,6 +22,7 @@ class SerializerField {
|
||||||
this.field = f;
|
this.field = f;
|
||||||
this.required = f.required;
|
this.required = f.required;
|
||||||
this.type = this.field.getAttribute("type");
|
this.type = this.field.getAttribute("type");
|
||||||
|
this.flatten = this.field.hasAttribute("flatten");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,13 +169,26 @@ class Serializer {
|
||||||
for (let key in f) {
|
for (let key in f) {
|
||||||
if (f[key]) {
|
if (f[key]) {
|
||||||
let d = f[key].serialize();
|
let d = f[key].serialize();
|
||||||
if (d !== null) {
|
if (d == null) {
|
||||||
if (k == "") {
|
continue
|
||||||
json[key] = d;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
json[k][key] = d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(k == "") {
|
||||||
|
if(f[key].flatten){
|
||||||
|
json[key].push(d);
|
||||||
|
} else {
|
||||||
|
json[key] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if(f[key].flatten){
|
||||||
|
json[k].push(d);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
json[k][key] = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -246,7 +260,7 @@ class Validator {
|
||||||
|
|
||||||
let v = Validator.validateRequired(sf);
|
let v = Validator.validateRequired(sf);
|
||||||
if (!v.valid) {
|
if (!v.valid) {
|
||||||
console.log(e.errors);
|
console.error(e.errors);
|
||||||
e.errors[sf.name].push(v.errors);
|
e.errors[sf.name].push(v.errors);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue