ソースを参照

Improve matcher example (see #4668)

alexweissman 7 年 前
コミット
b61b7f4892
1 ファイル変更11 行追加1 行削除
  1. 11 1
      pages/11.searching/docs.md

+ 11 - 1
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) {