Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

官网Tree控件 可搜索的树筛选demo 算法bug #19232

Closed
1 task
ZhaoJianXXXXX opened this issue Oct 15, 2019 · 3 comments
Closed
1 task

官网Tree控件 可搜索的树筛选demo 算法bug #19232

ZhaoJianXXXXX opened this issue Oct 15, 2019 · 3 comments
Assignees
Labels

Comments

@ZhaoJianXXXXX
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://ant.design/components/tree-cn/

Steps to reproduce

在可搜索的树demo中

const title = 'anything';

const searchValue= 'n';

const index = item.title.indexOf(searchValue);

const beforeStr = item.title.substr(0, index);

const afterStr = item.title.substr(index searchValue.length);

const title =
index > -1 ? (

{beforeStr}
<span style={{ color: '#f50' }}>{searchValue}

{afterStr}

) : (
{item.title}
);

对于title的拼接算法有误

What is expected?

当搜索项中有重复的值的时候
每一个所筛选的值都应该标红或其他显著标识
比如说搜索输入栏搜索“啊”
那么加入有一个搜索项“啊/啊/啊”中的每个“啊”都应该有所改变

const name = 'anything';

const searchValue= 'n';

const index = item.title.indexOf(searchValue);

let title = <React.Fragment>{ name }</React.Fragment>;
if(index > -1){
const otherStringArr = name.split(searchValue);
title = <React.Fragment/>;
for(let i = 0; i < otherStringArr.length; i ){
title = (
<React.Fragment>
{ title }
{ otherStringArr[i] }
{ i < otherStringArr.length - 1 ? <span style={{ color: '#f50' }}>{ searchValue } : null }
</React.Fragment>
)
}
}

What is actually happening?

目前只改变了第一个搜索值,使其变为红色,如果title中仍有与searchValue相同的值,并没有处理
比如说搜索输入栏搜索“啊”
那么加入有一个搜索项“啊/啊/啊”中的只有第一个“啊”的颜色有所改变

Environment Info
antd 3.23.6
React 任意版本
System win10
Browser 搜狗浏览器 8.6.1.31486
@zombieJ
Copy link
Member

zombieJ commented Oct 15, 2019

Demo 只是举例,实际业务中按照自己的需求改造即可。

@zombieJ zombieJ added the Usage label Oct 15, 2019
@ant-design-bot
Copy link
Contributor

Hello @ZhaoJianXXXXX, we use GitHub issues to trace bugs or discuss plans of Ant Design. So, please don't ask usage questions here. You can try to ask questions on Stack Overflow or Segment Fault, then apply tag antd and react to your question.

你好 @ZhaoJianXXXXX,Ant Design Issue 板块是用于 bug 反馈与需求讨论的地方。请勿询问如何使用的问题,你可以试着在 Stack Overflow 或者 Segment Fault 中提问(记得添加 antdreact 标签哦~)。

@afc163
Copy link
Member

afc163 commented Oct 15, 2019

也可以来个 PR 帮我们改进 : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants