解决方案

给物料插入如下配置,可以默认给物料提供 reloadDataSource 的参数。

  1. {
  2. title: {
  3. label: {
  4. type: 'i18n',
  5. 'en-US': 'reloadDataSource',
  6. 'zh-CN': 'reloadDataSource',
  7. },
  8. },
  9. name: 'reloadDataSource',
  10. setter: 'StringSetter',
  11. initialValue: () => (
  12. {
  13. "type": "JSFunction",
  14. "value": "function(){ return this.reloadDataSource; }"
  15. }
  16. ),
  17. },

在物料组件中,即可掉用如下代码来获取到相关方法。

  1. const reloadDataSource = props.getReloadDataSource()

FAQ

希望该配置在配置面板中不展示

在配置中加上

  1. condition: () => false,

完整示例

  1. {
  2. title: {
  3. label: {
  4. type: 'i18n',
  5. 'en-US': 'reloadDataSource',
  6. 'zh-CN': 'reloadDataSource',
  7. },
  8. },
  9. name: 'reloadDataSource',
  10. setter: 'StringSetter',
  11. condition: () => false,
  12. initialValue: () => (
  13. {
  14. "type": "JSFunction",
  15. "value": "function(){ return this.reloadDataSource; }"
  16. }
  17. ),
  18. },

配置没有生效

查看组件中的 schema,对应的配置是否已经正确设置。
image.png

没有正确设置上可能的原因是
1.snippets 中没有默认值
需要按照如下的代码中,加上默认的参数配置

  1. const snippets: Snippet[] = [
  2. {
  3. title: 'Field',
  4. screenshot: '',
  5. schema: {
  6. componentName: 'ProField',
  7. props: {
  8. type: 'textarea',
  9. value: '我是测试',
  10. getReloadDataSource: {
  11. "type": "JSFunction",
  12. "value": "function(){ return this.reloadDataSource; }"
  13. }
  14. },
  15. },
  16. },
  17. ];

如何全局生效

通过 https://www.yuque.com/lce/doc/mu7lml#LRXhp 来修改元数据信息,注意如果有 snippets 相关配置也需要修改相关的配置。