Skip to content

Commit e0158c5

Browse files
committed
Fixed single object - Bug:#4
1 parent 88c6438 commit e0158c5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

static/js/super-search.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@
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
}
@@ -129,4 +136,4 @@
129136
lastSearchResultHash = currentResultHash;
130137
});
131138

132-
})();
139+
})();

0 commit comments

Comments
 (0)