feat: support array within array in 3.x
This commit is contained in:
parent
8be05cabde
commit
d8e1c2c020
12
lib/list.js
12
lib/list.js
|
@ -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);
|
||||
|
|
|
@ -27,6 +27,9 @@ const json = {
|
|||
{label: 'work', id: 'x@sample.com'},
|
||||
{label: 'home', id: 'x@home.com'},
|
||||
],
|
||||
nestedArray: [
|
||||
[{msg: 'Hi'}],
|
||||
],
|
||||
tags: [],
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue