Skip to content

Commit 5653619

Browse files
committed
feat(Segment): 新增 data-cell 数据绑定方式
可在 segment-item 组件上使用如下方式绑定数据: <l-segment-item data-cell="测试数据" /> 该数据可在 bind:linchange 事件中获取 close #973
1 parent e2b5ce3 commit 5653619

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/segment/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Component({
9191
* 组件的初始数据
9292
*/
9393
data: {
94+
// segment-item 绑定的 data-cell 数据
95+
_cells:[],
9496
tabList: [],
9597
currentIndex: 0,
9698
_segmentItemInstances: []
@@ -107,16 +109,20 @@ Component({
107109
if (items.length === this.data.tabList.length && this.data._segmentItemInstances.indexOf(segmentItemInstance) > 0) return;
108110
let activeKey = val,
109111
currentIndex = this.data.currentIndex;
112+
let _cells = [];
110113
const tab = items.map((item, index) => {
111114
activeKey = !val && index === 0 ? item.data.key : activeKey;
112115
currentIndex = item.data.key === activeKey ? index : currentIndex;
116+
// 存储 segment-item 绑定的 data-cell 数据
117+
_cells[index] = item.dataset.cell;
113118
return {
114119
...item.data
115120
};
116121
});
117122
this.setData({
118-
tabList: tab,
123+
_cells,
119124
activeKey,
125+
tabList: tab,
120126
currentIndex,
121127
_segmentItemInstances: items
122128
}, () => {
@@ -150,7 +156,8 @@ Component({
150156
});
151157
this.triggerEvent('linchange', {
152158
activeKey,
153-
currentIndex
159+
currentIndex,
160+
cell:this.data._cells[currentIndex]
154161
});
155162
}
156163
}

0 commit comments

Comments
 (0)