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

addBuiltinComponentAction 时机能否获取组件的 this scope 值? #3008

Open
arleyGuoLei opened this issue Apr 24, 2024 · 3 comments
Open

Comments

@arleyGuoLei
Copy link

背景:想给组件增加一个 action 操作获取当前组件的 this 值,用来做数据绑定的时候方便找到具体层级。

想通过 https://lowcode-engine.cn/site/docs/api/material#%E8%AE%BE%E8%AE%A1%E5%99%A8%E8%BE%85%E5%8A%A9%E5%B1%82 时机获取组件 this 值。

  material.addBuiltinComponentAction({
    name: 'myIconName',
    content: {
      icon: () => 'x',
      title: 'hover title',
      action(node) {
        console.log('log =>  ~ action ~ node:', node)
        console.log('myIconName 扩展位被点击')
      },
    },
    important: true,
    condition: true,
  })

目前获取到的 node 如下图:

image

https://lowcode-engine.cn/site/docs/api/model/node

想要获取的 this 如下,现在都通过console 去调试找数据,很麻烦
image

image


大概调试了下,没找到 node 怎么获取到 scope/this

image

@arleyGuoLei
Copy link
Author

Node 是不是还没渲染,还是一个未运行的组件,所以获取不到 this?那还有更好的方案和时机获取编辑器组件渲染时的this 值么

@arleyGuoLei
Copy link
Author

ReactNode 是一个类型,它代表了可以被渲染的东西。这包括 ReactElement(即 JSX 返回的东西),字符串和数字(它们在渲染时会被转换为文本节点),以及数组或片段,它们可以让你返回多个元素。ReactNode 也可以是 null 或 undefined,表示不渲染任何东西。

咱们的 Node 是类似 ReactNode 的吗?所以如果要获取的话应该考虑获取到 node 的 ref 实例后再获取?

@arleyGuoLei
Copy link
Author

arleyGuoLei commented Apr 29, 2024

#1181

类似需求:期望可以通过API同步获取模拟器内 Page / Component 节点的 state 数据,目的是方便开发过程中时刻了解当前的数据值

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

No branches or pull requests

1 participant