修复 cell 在元素更新后,边框会不显示的问题 (#236)

This commit is contained in:
Yao 2018-05-11 14:14:03 +08:00 committed by GitHub
parent 0e49ef92ac
commit 18485e2393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View File

@ -1,18 +1,39 @@
let cellUpdateTimeout = 0;
Component({ Component({
relations: { relations: {
'../cell/index': { '../cell/index': {
type: 'child', type: 'child',
linked() {} linked() {
this._updateIsLastCell();
},
linkChanged() {
this._updateIsLastCell();
},
unlinked() {
this._updateIsLastCell();
}
} }
}, },
ready() {
let cells = this.getRelationNodes('../cell/index');
if (cells.length > 0) { methods: {
let lastIndex = cells.length - 1; _updateIsLastCell() {
// 用 setTimeout 减少计算次数
if (cellUpdateTimeout > 0) {
return;
}
cells.forEach((cell, index) => { cellUpdateTimeout = setTimeout(() => {
if (index < lastIndex) cell.notLastCell(); cellUpdateTimeout = 0;
let cells = this.getRelationNodes('../cell/index');
if (cells.length > 0) {
let lastIndex = cells.length - 1;
cells.forEach((cell, index) => {
cell.updateIsLastCell(index === lastIndex);
});
}
}); });
} }
} }

View File

@ -72,8 +72,10 @@ Component({
this.navigateTo(); this.navigateTo();
} }
}, },
notLastCell() {
this.setData({ isLastCell: false }); // 用于被 cell-group 更新,标志是否是最后一个 cell
updateIsLastCell(isLastCell) {
this.setData({ isLastCell });
} }
} }
}); });