json-forms 多个字段的自定义渲染器测试器

问题描述 投票:0回答:1

我用它的测试器创建了一个自定义渲染器:

import { rankWith, scopeEndsWith } from '@jsonforms/core'

export default rankWith(
  3, //increase rank as needed
  scopeEndsWith('uiSchema')
)

并且工作正常; 但我不知道如何更新此测试器以匹配其他字段(不仅仅是范围以“uiSchema”结尾的字段,所以让我们举个例子,我希望这个自定义渲染器用于范围以“”结尾的字段uiSchema' 和 'uiDescription');

jsonforms
1个回答
0
投票

我发现检查 jsonforms 中的测试人员源代码,它提供了

and
or
功能来组合测试人员

import { rankWith, scopeEndsWith, or } from '@jsonforms/core'

export default rankWith(
  3, //increase rank as needed
  or(scopeEndsWith('name'), scopeEndsWith('description'))
)

无论如何,测试器只是一个接收 3 个参数的函数,你可以编写自己的函数,在里面做任何你想做的事情;你只需要返回一个布尔值告诉 jsonforms 渲染器是否需要排名:

import { rankWith, scopeEndsWith, or } from '@jsonforms/core'

export default rankWith(
  3, //increase rank as needed
  (uischema, schema, context) => {
    // avoid using the renderer if it's a layout
    if (uischema.type === 'Control') {
      // test whatever you want...
      return true
    }
    return false
  }
)
© www.soinside.com 2019 - 2024. All rights reserved.