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 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" : {
Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff line change 22 data : {
33 inputShowed : false ,
44 inputVal : "" ,
5- i : 0
65 } ,
76 onLoad ( ) {
87 this . setData ( {
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 )
2120 } , 200 )
2221
2322 }
24- this . setData ( {
25- i : this . data . i + 1
26- } )
2723 } )
2824 } ,
2925 selectResult : function ( e ) {
You can’t perform that action at this time.
0 commit comments