File tree Expand file tree Collapse file tree 3 files changed +13
-28
lines changed
tools/demo/example/searchbar Expand file tree Collapse file tree 3 files changed +13
-28
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " weui-miniprogram" ,
3
- "version" : " 0.1.11 " ,
3
+ "version" : " 0.1.12 " ,
4
4
"description" : " " ,
5
5
"main" : " miniprogram_dist/index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -42,9 +42,7 @@ Component({
42
42
} ,
43
43
lastSearch : Date . now ( ) ,
44
44
lifetimes : {
45
- // @ts -ignore
46
45
attached ( ) {
47
- // @ts -ignore
48
46
if ( this . data . focus ) {
49
47
this . setData ( {
50
48
searchState : true ,
@@ -54,22 +52,15 @@ Component({
54
52
} ,
55
53
methods : {
56
54
clearInput ( ) {
57
- // @ts -ignore
58
55
this . setData ( {
59
56
value : '' ,
60
57
} )
61
- // @ts -ignore
62
58
this . triggerEvent ( 'clear' )
59
+ this . inputChange ( { detail : { value : '' } } , true )
63
60
} ,
64
- // @ts -ignore
65
61
inputFocus ( e ) {
66
- // this.setData({
67
- // searchState: true
68
- // })
69
- // @ts -ignore
70
62
this . triggerEvent ( 'focus' , e . detail )
71
63
} ,
72
- // @ts -ignore
73
64
inputBlur ( e ) {
74
65
this . setData ( {
75
66
focus : false ,
@@ -87,31 +78,29 @@ Component({
87
78
searchState : false ,
88
79
} )
89
80
} ,
90
- // @ts -ignore
91
- inputChange ( e ) {
81
+ inputChange ( e , dontTriggerInput ) {
92
82
this . setData ( {
93
83
value : e . detail . value
94
84
} )
95
- this . triggerEvent ( 'input' , e . detail )
85
+ if ( ! dontTriggerInput ) {
86
+ this . triggerEvent ( 'input' , e . detail )
87
+ }
96
88
if ( Date . now ( ) - this . lastSearch < this . data . throttle ) {
97
89
return
98
90
}
99
91
if ( typeof this . data . search !== 'function' ) {
100
92
return
101
93
}
102
94
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
110
98
} )
111
- } , this . data . throttle )
99
+ } ) . catch ( err => {
100
+ console . log ( 'search error' , err )
101
+ } )
112
102
113
103
} ,
114
- // @ts -ignore
115
104
selectResult ( e ) {
116
105
const { index} = e . currentTarget . dataset
117
106
const item = this . data . result [ index ]
Original file line number Diff line number Diff line change 2
2
data : {
3
3
inputShowed : false ,
4
4
inputVal : "" ,
5
- i : 0
6
5
} ,
7
6
onLoad ( ) {
8
7
this . setData ( {
11
10
} ,
12
11
search : function ( value ) {
13
12
return new Promise ( ( resolve , reject ) => {
14
- if ( this . data . i % 2 === 0 ) {
13
+ if ( value ) {
15
14
setTimeout ( ( ) => {
16
15
resolve ( [ { text : '搜索结果' , value : 1 } , { text : '搜索结果2' , value : 2 } ] )
17
16
} , 200 )
21
20
} , 200 )
22
21
23
22
}
24
- this . setData ( {
25
- i : this . data . i + 1
26
- } )
27
23
} )
28
24
} ,
29
25
selectResult : function ( e ) {
You can’t perform that action at this time.
0 commit comments