Skip to content

解决index索引组件存在的2个bug(1.索引首位字母定位不准确2.滑动超出边界报错) #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions dist/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,16 @@ Component({
triggerCallback(options){
this.triggerEvent('change',options)
},
handlerFixedTap(event){
const eindex = event.currentTarget.dataset.index;
const item = this.getCurrentItem(eindex);
this.setData({
scrollTop : item.top,
currentName : item.currentName,
isTouches : true
})
this.triggerCallback({
index : eindex,
current : item.currentName
})
},
handlerTouchMove(event){
const data = this.data;
const touches = event.touches[0] || {};
const pageY = touches.pageY;
const rest = pageY - data.startTop;
let index = Math.ceil( rest/data.itemHeight );
let index = Math.floor( rest/data.itemHeight );
index = index >= data.itemLength ? data.itemLength -1 : index;
if(index<0){
return ;
}
const movePosition = this.getCurrentItem(index);

/*
Expand Down Expand Up @@ -155,4 +145,4 @@ Component({
}).exec()
}
}
})
})
2 changes: 1 addition & 1 deletion dist/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
wx:for="{{fixedData}}"
wx:key="{{index}}"
data-index="{{index}}"
catchtap="handlerFixedTap">
>
{{item}}
</view>
</view>
Expand Down
20 changes: 5 additions & 15 deletions src/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,16 @@ Component({
triggerCallback(options){
this.triggerEvent('change',options)
},
handlerFixedTap(event){
const eindex = event.currentTarget.dataset.index;
const item = this.getCurrentItem(eindex);
this.setData({
scrollTop : item.top,
currentName : item.currentName,
isTouches : true
})
this.triggerCallback({
index : eindex,
current : item.currentName
})
},
handlerTouchMove(event){
const data = this.data;
const touches = event.touches[0] || {};
const pageY = touches.pageY;
const rest = pageY - data.startTop;
let index = Math.ceil( rest/data.itemHeight );
let index = Math.floor( rest/data.itemHeight );
index = index >= data.itemLength ? data.itemLength -1 : index;
if(index<0){
return ;
}
const movePosition = this.getCurrentItem(index);

/*
Expand Down Expand Up @@ -155,4 +145,4 @@ Component({
}).exec()
}
}
})
})
2 changes: 1 addition & 1 deletion src/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
wx:for="{{fixedData}}"
wx:key="{{index}}"
data-index="{{index}}"
catchtap="handlerFixedTap">
>
{{item}}
</view>
</view>
Expand Down