- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
场景:我有一个文本框,下面是一个数据列表。当我在文本框中键入内容时,列表会根据文本框中的文本进行过滤。
代码:
管道:
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(xxxs: IXxx[], searchInput: string): IXxx[] {
if (!xxxs) {
return [];
}
if (!searchInput) {
return xxxs;
}
searchInput = searchInput.toLowerCase();
return xxxs.filter(xxx => {
let firstName = xxx.employee.firstName.toLowerCase();
let lastName = xxx.employee.lastName.toLowerCase();
return firstName.includes(searchInput) &&
firstName.startsWith(searchInput[0]) ||
lastName.includes(searchInput) &&
lastName.startsWith(searchInput[0]);
});
}
}
HTML:
<input type="text" placeholder="search person"
[(ngModel)]="searchText" />
...
<section * ngFor="let shift of shifts | search: searchText; let last = last">
...
</section>
<div * ngIf="searchText && (shifts | search: searchText).length === 0" class="no-content">
No Shifts</div>
此代码适用于除 IE 和 Edge 之外的所有浏览器。为 includes
和 startsWith
添加了 polyfill,但仍然显示错误。
错误:
更新 #1:
我尝试了 consoling searchText,默认值设置为空字符串(即“”),当我键入内容时它会显示在控制台中。使用调试器时,我没有收到此错误。奇怪。
最佳答案
用 indexOf()
方法代替 includes()
尝试一次。对于 startswith()
,请在此处查看 polyfill https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
关于angular - 无法获取未定义或空引用的属性 'toLowerCase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57370286/
我正在使用 AutoComplete API Material UI。有一个 的对象top100电影其中包含电影的标题和年份。如果我使用 top100Film.title 搜索,我的自动完成工作正常如
我想知道为什么 Character.toUpperCase/toLowerCase 没有像 String.toUpperCase/toLowerCase 这样的 Locale 参数。 我必须首先将可以
我有一个名为 Profiles 的集合,其中包含一个名为 emails 的数组。 我想将数组中的所有电子邮件字符串更改为小写。 db.Profiles.update({"emails":/@/i},
我在尝试处理的 Angular 错误消息时遇到问题。我试图确保确认电子邮件的不区分大小写不适用于初始电子邮件地址。 在我的 Controller 中,我使用了 toLowerCase() 过滤器...
我对 JavaScript 还很陌生。我需要两件事: 干燥我的代码。具体来说,{leo} 对象的 hasMoreOscarsThan 方法内部声明了很多变量。我需要在对象 {jenn}、{sam}、{
在土耳其语中,有一个字母 I,它是 i 的大写形式。当我将其转换为小写时,我得到了一个奇怪的结果。例如: var string_tr = "İ".toLowerCase(); var string_e
我有这段代码,它正在从文本框中读取值,我认为在尝试 parseInt() 之前检查 '' 是安全的,但显然不是。 我收到错误: Uncaught TypeError: Cannot call meth
找不到问题,但是一直显示这个错误!!使用 includes 等其他方法时也会发生同样的情况。 let notes = [{},{ title: 'My next trip', body
我正在尝试重构我的 js 代码以使其更加干练,但遇到了这个错误。这是我的代码 function validate_field(e){ console.log(typeof e); $(
我是 javascript 的新手,正在上几堂课。我想知道在 toLowerCase 命令末尾使用括号,因为即使你在它们之间放一个数字,它们也不会做任何事情。 谁能解释一下它们的用途? 最佳答案 to
什么更有效率?: var text="ABCdef"; var lowerVersion=text.toLowerCase(); if (lowerVersion=='abcdef' || lower
为什么 JS 对大写的 i (?) 有问题,而 javascript 对大写的 ş,ö,ç,ğ,ü (Ş,Ö,Ç,Ğ,Ü),如下所述? (问题与字母位置无关。) "İş".toLowerCase().
我知道这个问题已经被提出太多次了,但没有一个问题能解决我遇到的问题。每次运行该函数时都会出现以下错误: TypeError: Cannot read property 'toLowerCase' of
console.log("HİNDİ".toLocaleLowerCase() == "hindi"); console.log("HİNDİ" == "hindi"); console.log("H
我对这个符号有疑问——(不是——)。当我使用 tolowercase() 函数时,它显示 ����。我不知道如何解决这个问题。请帮忙。谢谢。 public String content = "nois
场景:我有一个文本框,下面是一个数据列表。当我在文本框中键入内容时,列表会根据文本框中的文本进行过滤。 代码: 管道: @Pipe({ name: 'search' }) export class
我有一个读取推文并尝试匹配关键字的小应用程序,我注意到特定字符串的这种奇怪行为: var text = "The Νіkе Dunk Ніgh ЅΒ 'Uglу Ѕwеаtеr' іѕ n
JSTL fn:toLowerCase() 函数与 fn:toUpperCase() 函数作用相反,用来将指定字符串中的所有字符转为小写。 语法 JSP fn:toLowerCase() 函数的
我想制作一个以小写形式返回估算文本的输入字段。我正在使用博览会 const [login, setLogin] = useState(''); //... setLogin(val.toLowerCa
我正在尝试将我的 React Native 更新到最新版本。我运行命令:react-native upgrade --verbose 但是,它正在返回: info No version passed.
我是一名优秀的程序员,十分优秀!