浏览代码

Use a single if for a better readable source code

Dustin Utecht 3 年之前
父节点
当前提交
69fad777f2
共有 1 个文件被更改,包括 24 次插入29 次删除
  1. 24 29
      src/extensions/filter-control/bootstrap-table-filter-control.js

+ 24 - 29
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -216,7 +216,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
         keys.forEach(key => {
           const thisColumn = that.columns[that.fieldsColumnsIndex[key]]
-          const rawFilterValue = (filterPartial[key] || '');
+          const rawFilterValue = (filterPartial[key] || '')
           const filterValue = rawFilterValue.toLowerCase()
           let value = Utils.unescapeHTML(Utils.getItemField(item, key, false))
           let tmpItemIsExpected
@@ -239,36 +239,31 @@ $.BootstrapTable = class extends $.BootstrapTable {
             if ($.inArray(key, that.header.fields) !== -1) {
               if (value === undefined || value === null) {
                 tmpItemIsExpected = false
+              } else if (typeof value === 'object' && thisColumn.filterCustomSearch) {
+                itemIsExpected.push(that.isValueExpected(rawFilterValue, value, thisColumn, key))
+                return
               } else if (typeof value === 'object' && Array.isArray(value)) {
-                if (thisColumn.filterCustomSearch) {
-                  tmpItemIsExpected = that.isValueExpected(rawFilterValue, value, thisColumn, key)
-                } else {
-                  value.forEach(objectValue => {
-                    if (tmpItemIsExpected) {
-                      return
-                    }
-
-                    if (this.options.searchAccentNeutralise) {
-                      objectValue = Utils.normalizeAccent(objectValue)
-                    }
-                    tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
-                  })
-                }
+                value.forEach(objectValue => {
+                  if (tmpItemIsExpected) {
+                    return
+                  }
+
+                  if (this.options.searchAccentNeutralise) {
+                    objectValue = Utils.normalizeAccent(objectValue)
+                  }
+                  tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
+                })
               } else if (typeof value === 'object' && !Array.isArray(value)) {
-                if (thisColumn.filterCustomSearch) {
-                  tmpItemIsExpected = that.isValueExpected(rawFilterValue, value, thisColumn, key)
-                } else {
-                  Object.values(value).forEach(objectValue => {
-                    if (tmpItemIsExpected) {
-                      return
-                    }
-
-                    if (this.options.searchAccentNeutralise) {
-                      objectValue = Utils.normalizeAccent(objectValue)
-                    }
-                    tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
-                  })
-                }
+                Object.values(value).forEach(objectValue => {
+                  if (tmpItemIsExpected) {
+                    return
+                  }
+
+                  if (this.options.searchAccentNeutralise) {
+                    objectValue = Utils.normalizeAccent(objectValue)
+                  }
+                  tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
+                })
               } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
                 if (this.options.searchAccentNeutralise) {
                   value = Utils.normalizeAccent(value)