feat: support array within array in 3.x

This commit is contained in:
Hage Yaapa 2019-03-14 16:46:03 +05:30
parent 8be05cabde
commit d8e1c2c020
2 changed files with 13 additions and 2 deletions

View File

@ -64,7 +64,12 @@ function List(items, itemType, parent) {
}
List.prototype.toItem = function(item) {
return isClass(this.itemType) ? new this.itemType(item) : this.itemType(item);
if (isClass(this.itemType)) {
return new this.itemType(item);
} else {
if (Array.isArray(item)) return item;
else return this.itemType(item);
}
};
items.forEach(function(item, i) {
@ -91,7 +96,10 @@ List.prototype.push = function(obj) {
List.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
const items = [];
this.forEach(function(item) {
if (item && typeof item === 'object' && item.toObject) {
if (item && Array.isArray(item) && item.toArray) {
const subArray = item.toArray();
items.push(subArray);
} else if (item && typeof item === 'object' && item.toObject) {
items.push(item.toObject(onlySchema, removeHidden, removeProtected));
} else {
items.push(item);

View File

@ -27,6 +27,9 @@ const json = {
{label: 'work', id: 'x@sample.com'},
{label: 'home', id: 'x@home.com'},
],
nestedArray: [
[{msg: 'Hi'}],
],
tags: [],
};