如何过滤不区分大小写

时间:2016-10-05 05:13:30

标签: angular filter pipe

import {Pipe, PipeTransform} from '@angular/core';

// # Filter Array of Objects
@Pipe ({ name: 'filter' })
export class FilterArrayPipe implements PipeTransform  {
  transform(value:any, filter: string, item: any) {
    // filter = filter ? filter.toLocaleLowerCase() : null;
    if (!filter) {
      return value;
    } else if (value) {
      return value.filter(item=> {
        for (let key in item) {
          if ((typeof item[key] === 'string' || item[key] instanceof String) &&
            (item[key].indexOf(filter) !== -1)) {
            return true;
          }
        }
      });
    }
  }
}

2 个答案:

答案 0 :(得分:4)

在比较之前将它们转换为小写:

(item[key].toLowerCase().indexOf(filter.toLowerCase()) !== -1)) {

答案 1 :(得分:-2)

    public boolean accessibilityEnable(Context context) {
        boolean enable = false;
        Log.e("Reached before function", "yes");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            try {
                AccessibilityManager manager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
                List<AccessibilityServiceInfo> serviceList = manager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN);
                Log.e("Reached before for loop", "yes");
                for (AccessibilityServiceInfo serviceInfo : serviceList) {
                    String name = serviceInfo.getSettingsActivityName();

                    if (!TextUtils.isEmpty(name) && name.equals(TALKBACK_SETTING_ACTIVITY_NAME)) {
                        enable = true;
                        Log.e("Reached after if loop", "yes");
                    }
                }
                Log.e("Reached after for loop", "yes");
            } catch (Exception e) {
                Log.e("Error", "Error aaya re");
            }
        }
        return enable;
    }