Skip to content

Commit

Permalink
Fixed single object - Bug:#4
Browse files Browse the repository at this point in the history
  • Loading branch information
agusmakmun committed Jan 18, 2017
1 parent 88c6438 commit e0158c5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions static/js/super-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@
}
searchResultsEl.style.offsetWidth;

var matchingPosts = posts.filter(function (post) {
if ((post.title + '').toLowerCase().indexOf(currentInputValue) !== -1 || (post.description + '').toLowerCase().indexOf(currentInputValue) !== -1) {
return true;
}
});
var matchingPosts;
// check the `posts` object is single or many objects.
// if posts.title === undefined, so posts is many objects.
if(posts.title === undefined) {
matchingPosts = posts.filter(function (post) {
if ((post.title + '').toLowerCase().indexOf(currentInputValue) !== -1 || (post.description + '').toLowerCase().indexOf(currentInputValue) !== -1) {
return true;
}
});
}else {
matchingPosts = [posts]; // assign single object to Array
}
if (!matchingPosts.length) {
searchResultsEl.classList.add('is-hidden');
}
Expand All @@ -129,4 +136,4 @@
lastSearchResultHash = currentResultHash;
});

})();
})();

1 comment on commit e0158c5

@agusmakmun
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue posts.filter is not a function: chinchang/super-search#3

Please sign in to comment.