/
repeat-vertical.js
55 lines (40 loc) · 1.36 KB
/
repeat-vertical.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const BaseLayoutComponent = require('./base-layout-component.js');
module.exports = class RepeatVertical extends BaseLayoutComponent {
constructor(properties) {
super(properties);
this.template = properties.template;
this._children = [];
}
generateComponent(document, data) {
super.generateComponent(document, data);
const values = this.getBinding(data);
if (!values || !values.length) {
// invalid data binding
return;
}
let offsetY = 0;
for (let index = values._index || 0; index < values.length; index++) {
values._index = index;
const value = values[index];
const child = this.template.clone();
child.width = this.width - this.margin.horizontalTotal;
child._originX = this._originX + this.margin.left;
child._originY = offsetY + this._originY + this.margin.top;
child.initializeComponent(value);
child.layoutComponent(document);
if (child._originY + child.height > this._originY + this.height) {
document.renderNextPage = true;
return;
}
child.generateComponent(document, value);
this._children.push(child);
offsetY += child.height;
}
}
afterGenerateComponent(document) {
super.afterGenerateComponent(document);
for (let child of this._children) {
child.afterGenerateComponent(document);
}
}
}