From b61b7f48922adbf277427a0d26fa330090378912 Mon Sep 17 00:00:00 2001 From: alexweissman Date: Wed, 13 Sep 2017 19:34:37 -0400 Subject: [PATCH] Improve matcher example (see #4668) --- pages/11.searching/docs.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pages/11.searching/docs.md b/pages/11.searching/docs.md index 7ffbd4ca..5f1af988 100644 --- a/pages/11.searching/docs.md +++ b/pages/11.searching/docs.md @@ -21,7 +21,12 @@ function matchCustom(params, data) { if ($.trim(params.term) === '') { return data; } - + + // Do not display the item if there is no 'text' property + if (typeof data.text === 'undefined') { + return null; + } + // `params.term` should be the term that is used for searching // `data.text` is the text that is displayed for the data object if (data.text.indexOf(params.term) > -1) { @@ -64,6 +69,11 @@ function matchStart(params, data) { return data; } + // Skip if there is no 'children' property + if (typeof data.children === 'undefined') { + return null; + } + // `data.children` contains the actual options that we are matching against var filteredChildren = []; $.each(data.children, function (idx, child) {