gpt4 book ai didi

javascript - 自定义小部件未显示在 mozilla-services-react-jsonschema-form 中

转载 作者:行者123 更新时间:2023-11-30 20:22:42 26 4
gpt4 key购买 nike

我使用 mozilla-react-jsonschema-form 创建了一个带有自定义字段的简单表单,我的代码如下

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

import Form from "react-jsonschema-form";

const schema = {
title: "Todo",
type: "object",
required: ["title"],
properties: {
title: {type: "string", title: "Title", default: ""},
done: {type: "boolean", title: "Done?", default: false}
}
};

const MyCustomWidget = (props) => {
return (
<input type="text"
className="custom"
value={props.value}
required={props.required}
onChange={(event) => props.onChange(event.target.value)} />
);
};

const widgets = {
myCustomWidget: MyCustomWidget
};

const uiSchema = {
"ui:widget": "myCustomWidget"
}

const log = (type) => console.log.bind(console, type);

class App extends Component {
render() {
return (
<Form schema={schema}

onSubmit={log("submitted")}
onError={log("errors")}
uiSchema={uiSchema}
widgets={widgets} />
);
}
}

export default App;

默认字段已创建,但自定义小部件未出现在表单中。,还是我做错了什么

最佳答案

尝试改变你的代码

const uiSchema = {  "ui:widget": "myCustomWidget"}

const uiSchema ={ title:{"ui:widget": "myCustomWidget"}}

关于javascript - 自定义小部件未显示在 mozilla-services-react-jsonschema-form 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51290327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com