我對js和react很陌生,所以我希望有人能給我一個關于這個問題的想法。我的解決方案非常糟糕,但我想不出一個好的解決方案。我也不知道如何在渲染中添加 if-else 陳述句。有 6 個按鈕,每個按鈕都是一個 json-schema 的名稱(最好有一個表格而不是按鈕,但我在使用 tableview 時總是出錯)。我想在用戶單擊按鈕時顯示 json-schema,以便用戶可以提交 json 檔案。
import React, { Component, useState } from 'react';
import { Row, Col } from 'react-bootstrap';
import { withTheme } from '@rjsf/core';
import schema1 from '../schemas/schema1.json';
import schema2 from '../schemas/schema2.json';
import { Datagrid, TextField, EditButton, DeleteButton } from 'react-admin';
class MyApp extends Component {
constructor(props) {
super(props);
this.clickme = this.clickme.bind(this);
}
ToggleGroup() {
const theme = {
blue: {
default: '#3f51b5',
hover: '#283593',
},
pink: {
default: '#000000',
hover: '#ad1457'
}
}
return (<div>
{types.map(type => (
<Col>
<Col>
<Button
active={active === type}
>{type}</Button>
</Col>
</Col>
))}
<Col>
<Form
schema={schema1}
/>
</Col>
</div>
);
}
render() {
return (
<>
<Col>
<Col>
<text>
List of schemas
</text>
</Col>
</Col>
<this.ToggleGroup />
</>
);
}
}
export default MyApp;
uj5u.com熱心網友回復:
您的問題似乎主要與如何構建代碼有關。這是你可以通過研究其他人的代碼來最好地學習的東西。這個github 存盤庫包含很多很棒的零碎內容可以幫助您。
要回答您的問題,我建議您將組件分開。解決方案本身可能對您來說很清楚。也許您可以將架構添加到物件/映射,然后根據activeType您在ToggleGroup.
例如:
import schema1 from '../schemas/schema1.json';
...
const schemas = new Map([
['schema1', schema1],
['schema2', schema2],
...
]);
// In your Form-Component
const activeSchema = schemas.get('activeType')
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/376094.html
標籤:反应 json jsonschema
