Yao 876c75a388
[improvement] Field: 优化在列表中输入框表现 (#296)
* 优化 field 实现

* field 使用cell来架构

* field 列表
2018-06-04 21:52:32 +08:00

59 lines
1.3 KiB
JavaScript

const CELL_PATH = '../cell/index';
const FIELD_PATH = '../field/index'
Component({
relations: {
[CELL_PATH]: {
type: 'child',
linked() {
this._updateIsLastElement(CELL_PATH);
},
linkChanged() {
this._updateIsLastElement(CELL_PATH);
},
unlinked() {
this._updateIsLastElement(CELL_PATH);
}
},
[FIELD_PATH]: {
type: 'child',
linked() {
this._updateIsLastElement(FIELD_PATH);
},
linkChanged() {
this._updateIsLastElement(FIELD_PATH);
},
unlinked() {
this._updateIsLastElement(FIELD_PATH);
}
}
},
data: {
elementUpdateTimeout: 0
},
methods: {
_updateIsLastElement(childPath) {
// 用 setTimeout 减少计算次数
if (this.data.elementUpdateTimeout > 0) {
return;
}
const elementUpdateTimeout = setTimeout(() => {
this.setData({ elementUpdateTimeout: 0 });
let elements = this.getRelationNodes(childPath);
if (elements.length > 0) {
let lastIndex = elements.length - 1;
elements.forEach((cell, index) => {
cell.updateIsLastElement(index === lastIndex);
});
}
});
this.setData({ elementUpdateTimeout });
}
}
});