Update _appendMultiple to support general iterables
This commit is contained in:
parent
93f7278586
commit
168bd72d0a
@ -301,22 +301,28 @@ class DisplayGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static _appendMultiple(container, createItem, detailsArray, fallback=[]) {
|
static _appendMultiple(container, createItem, detailsIterable, fallback=[]) {
|
||||||
if (container === null) { return 0; }
|
if (container === null) { return 0; }
|
||||||
|
|
||||||
const isArray = Array.isArray(detailsArray);
|
const multi = (
|
||||||
if (!isArray) { detailsArray = fallback; }
|
detailsIterable !== null &&
|
||||||
|
typeof detailsIterable === 'object' &&
|
||||||
|
typeof detailsIterable[Symbol.iterator] !== 'undefined'
|
||||||
|
);
|
||||||
|
if (!multi) { detailsIterable = fallback; }
|
||||||
|
|
||||||
container.dataset.multi = `${isArray}`;
|
let count = 0;
|
||||||
container.dataset.count = `${detailsArray.length}`;
|
for (const details of detailsIterable) {
|
||||||
|
|
||||||
for (const details of detailsArray) {
|
|
||||||
const item = createItem(details);
|
const item = createItem(details);
|
||||||
if (item === null) { continue; }
|
if (item === null) { continue; }
|
||||||
container.appendChild(item);
|
container.appendChild(item);
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return detailsArray.length;
|
container.dataset.multi = `${multi}`;
|
||||||
|
container.dataset.count = `${count}`;
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _appendFurigana(container, segments, addText) {
|
static _appendFurigana(container, segments, addText) {
|
||||||
|
Loading…
Reference in New Issue
Block a user