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

给 Group 增加 findByClassName 方法 #301

Closed
1 task
Yanyan-Wang opened this issue Dec 10, 2019 · 3 comments · Fixed by #304
Closed
1 task

给 Group 增加 findByClassName 方法 #301

Yanyan-Wang opened this issue Dec 10, 2019 · 3 comments · Fixed by #304

Comments

@Yanyan-Wang
Copy link
Contributor

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

What problem does this feature solve?

在 addShape 时 attrs 中有一个 string 类型的属性 className。可以通过 group.findByClassName('classnamexxx') 找到对应的 shape。

What does the proposed API look like?

API

/**
 * 在该组中查找 shape
 * @param {string} classname 根据 classname 查找,与 addShape 时写在 attrs 中的 className 对应。
 * @return {Shape[]} 返回所有 className 为 classname 的 Shape 列表
 */
findByClassName(classname);

USAGE

group.addShape('text', {
  attrs: {
    //...
      className: 'group-text'
  }
})
//....
let textShape = group.findByClassName('group-text')[0];
//...
@dengfuping
Copy link
Member

dengfuping commented Dec 10, 2019

  • 根据 元素名称 进行查找比较常用,因此 Group 只新增 findAllByName 方法:
/**
 * 根据 name 查找元素列表
 * @param {string}      name 元素名称
 * @return {IElement[]} 元素
 */
findAllByName(name: string): IElement[];
  • 其他查找方式可以通过传入自定义的 filter 函数实现, 比如 group.find(filterFn) 或者 group.findAll(filterFn)

@hustcc
Copy link
Member

hustcc commented Dec 10, 2019

感觉不如直接提供 querySelector 啊😂

@dengfuping
Copy link
Member

感觉不如直接提供 querySelector 啊😂

  • querySelector 要考虑的情况就比较多了,那样就会实现的比较重。基本上 findXXX 方法就够用了。

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

Successfully merging a pull request may close this issue.

3 participants