May I know how can I preserve the plain JSON object while I save to .json file and retrieve from the json file in the properly way.
const jsonObj = [
{
min:1,
max:4,
defaultValue:3,
width:"100%",
label:"Column",
onChange:(evt) => adjustGrid("col", evt),
type:"InputNumber"
},
{
min:1,
max:4,
defaultValue:1,
width:"100%",
label:"Row",
onChange:(evt) => adjustGrid("row", evt),
type:"InputNumber"
}
]
The intention of preserving the plain JSON object is because I want to achieve fully dynamic form element controls with the helps of JSON object.
I have attempted to use JSON.stringify but it escape the onChange key-pair which makes I cannot retrieve back the onChange key when I retrieve it from my .JSON file.
the onChange function is not restricted for adjustGrid function, it can be any function that has been defined in the JS file.
The render code will be:
return jsonObj.map((v) => {
return (
<Form.Item label={v.type}>
<InputNumber
min={v.defaultValue}
max={v.max}
defaultValue={v.defaultValue}
{...v}
width={v.width}
/>
</Form.Item>
)
});