fixed array of objects support for add()
This commit is contained in:
parent
d44346d7be
commit
21449685f1
|
@ -73,27 +73,44 @@
|
||||||
*/
|
*/
|
||||||
add(entry) {
|
add(entry) {
|
||||||
|
|
||||||
|
// for array of entries
|
||||||
if (Array.isArray(entry)) {
|
if (Array.isArray(entry)) {
|
||||||
|
// temp array
|
||||||
|
let entries = [];
|
||||||
|
|
||||||
entry.forEach(() => {
|
entry.forEach(() => {
|
||||||
|
// add id if not provided
|
||||||
if (!entry.id) {
|
if (!entry.id) {
|
||||||
entry.id = Math.random().toString(36).substr(2, 9);
|
entry.id = Math.random().toString(36).substr(2, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add entry to records collection
|
||||||
this.records.push(entry);
|
this.records.push(entry);
|
||||||
|
|
||||||
return entry;
|
// used to return all added
|
||||||
|
this.entries.push(entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
// save to storage
|
// save to storage
|
||||||
this._save();
|
this._save();
|
||||||
|
|
||||||
|
// return added entry(s)
|
||||||
|
return entries;
|
||||||
|
|
||||||
|
// if single entry
|
||||||
} else {
|
} else {
|
||||||
|
// add id if not provided
|
||||||
if (!entry.id) {
|
if (!entry.id) {
|
||||||
entry.id = Math.random().toString(36).substr(2, 9);
|
entry.id = Math.random().toString(36).substr(2, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add entry to records collection
|
||||||
this.records.push(entry);
|
this.records.push(entry);
|
||||||
|
|
||||||
// save to storage
|
// save to storage
|
||||||
this._save();
|
this._save();
|
||||||
|
|
||||||
|
// return added entry
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue