简体   繁体   English

使用react.js实现过滤器功能

[英]Implement filter functionality using react.js

First of all please have a look here. 首先请在这里看看。

[http://codepen.io/webmaster444/pen/yOxrNa][1]

Here you could notice that it searches names start with input but not whole names. 在这里,您可能会注意到它搜索名称的开头是输入,但不是全名。

For instance if you input touch then it returns no value. 例如,如果您输入touch,则它不返回任何值。 I want to return iPod touch. 我想退回iPod touch。 What can I do? 我能做什么?

In line 10 change 在第10行更改

if (item.name.toLowerCase().indexOf(input)) {

to

if (item.name.toLowerCase().indexOf(input) === -1) {

Don't rely on truthy or falsy values, do the proper conversion and use the === operator every time you have the slightest doubt on how a value such as an numeric value will be converted into boolean. 每次对如何将数值(例如数值)转换为布尔值存有一点疑问时,请不要依赖真实或虚假的值,进行正确的转换并使用===运算符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM