File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 110110 }
111111 searchResultsEl . style . offsetWidth ;
112112
113- var matchingPosts = posts . filter ( function ( post ) {
114- if ( ( post . title + '' ) . toLowerCase ( ) . indexOf ( currentInputValue ) !== - 1 || ( post . description + '' ) . toLowerCase ( ) . indexOf ( currentInputValue ) !== - 1 ) {
115- return true ;
116- }
117- } ) ;
113+ var matchingPosts ;
114+ // check the `posts` object is single or many objects.
115+ // if posts.title === undefined, so posts is many objects.
116+ if ( posts . title === undefined ) {
117+ matchingPosts = posts . filter ( function ( post ) {
118+ if ( ( post . title + '' ) . toLowerCase ( ) . indexOf ( currentInputValue ) !== - 1 || ( post . description + '' ) . toLowerCase ( ) . indexOf ( currentInputValue ) !== - 1 ) {
119+ return true ;
120+ }
121+ } ) ;
122+ } else {
123+ matchingPosts = [ posts ] ; // assign single object to Array
124+ }
118125 if ( ! matchingPosts . length ) {
119126 searchResultsEl . classList . add ( 'is-hidden' ) ;
120127 }
129136 lastSearchResultHash = currentResultHash ;
130137 } ) ;
131138
132- } ) ( ) ;
139+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments