Skip to content

Commit 6c40363

Browse files
committed
fix #34
1 parent 066e665 commit 6c40363

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weui-miniprogram",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "",
55
"main": "miniprogram_dist/index.js",
66
"scripts": {

src/searchbar/searchbar.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ Component({
4242
},
4343
lastSearch: Date.now(),
4444
lifetimes: {
45-
// @ts-ignore
4645
attached() {
47-
// @ts-ignore
4846
if (this.data.focus) {
4947
this.setData({
5048
searchState: true,
@@ -54,22 +52,15 @@ Component({
5452
},
5553
methods: {
5654
clearInput() {
57-
// @ts-ignore
5855
this.setData({
5956
value: '',
6057
})
61-
// @ts-ignore
6258
this.triggerEvent('clear')
59+
this.inputChange({detail: {value: ''}}, true)
6360
},
64-
// @ts-ignore
6561
inputFocus(e) {
66-
// this.setData({
67-
// searchState: true
68-
// })
69-
// @ts-ignore
7062
this.triggerEvent('focus', e.detail)
7163
},
72-
// @ts-ignore
7364
inputBlur(e) {
7465
this.setData({
7566
focus: false,
@@ -87,31 +78,29 @@ Component({
8778
searchState: false,
8879
})
8980
},
90-
// @ts-ignore
91-
inputChange(e) {
81+
inputChange(e, dontTriggerInput) {
9282
this.setData({
9383
value: e.detail.value
9484
})
95-
this.triggerEvent('input', e.detail)
85+
if (!dontTriggerInput) {
86+
this.triggerEvent('input', e.detail)
87+
}
9688
if (Date.now() - this.lastSearch < this.data.throttle) {
9789
return
9890
}
9991
if (typeof this.data.search !== 'function') {
10092
return
10193
}
10294
this.lastSearch = Date.now()
103-
this.timerId = setTimeout(() => {
104-
this.data.search(e.detail.value).then(json => {
105-
this.setData({
106-
result: json
107-
})
108-
}).catch(err => {
109-
console.log('search error', err)
95+
this.data.search(e.detail.value).then(json => {
96+
this.setData({
97+
result: json
11098
})
111-
}, this.data.throttle)
99+
}).catch(err => {
100+
console.log('search error', err)
101+
})
112102

113103
},
114-
// @ts-ignore
115104
selectResult(e) {
116105
const {index} = e.currentTarget.dataset
117106
const item = this.data.result[index]

tools/demo/example/searchbar/searchbar.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Page({
22
data: {
33
inputShowed: false,
44
inputVal: "",
5-
i: 0
65
},
76
onLoad() {
87
this.setData({
@@ -11,7 +10,7 @@ Page({
1110
},
1211
search: function (value) {
1312
return new Promise((resolve, reject) => {
14-
if (this.data.i % 2 === 0) {
13+
if (value) {
1514
setTimeout(() => {
1615
resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
1716
}, 200)
@@ -21,9 +20,6 @@ Page({
2120
}, 200)
2221

2322
}
24-
this.setData({
25-
i: this.data.i + 1
26-
})
2723
})
2824
},
2925
selectResult: function (e) {

0 commit comments

Comments
 (0)