使用JSON表单架构放置条件元素

I'm tinkering around with Mozillas JSON webform tool react-jsonschema-form [1] and struggling to define the placement of conditional cells.

考虑流程的简单形式:

|- item1 
|---conditionalitem
|- item2 

What I want to do, is use JSON schema to create conditional logic to render some intermediary commponent if some condition satisfies. I have done this and created a little demo to see [2]. Using this logic, a secondary component will get rendered if the option selected in the first select component is option2.

What I would like however, is the conditional component to render between item1 and item2. This can be achieved by appending item2 inside the dependency object but I want item2 to render regardless of any conditional logic. How would one achieve this?

提前致谢。

[1] https://github.com/rjsf-team/react-jsonschema-form
[2] https://codesandbox.io/s/red-fast-x9q0c?file=/src/App.js

评论
sesse
sesse

Yes. You can control the order in which the items get rendered. This is configurable in your uiSchema. Just add the below line in your uiSchema

"ui:order": ["item1", "item2","item1conditional"]

因此,App.js中的uiSchema将变为

const uiSchema = {
 "ui:order": ["item1", "item2","item1conditional"],
 description: {
   "ui:widget": "textarea",
   classNames: "foo"
 }
};

确保添加将来添加的所有项目,否则会引发错误。

点赞
评论