打字稿 - 铸造字符串到自定义复杂对象
我有一个由自动化系统返回的字符串。
"[
{
key: "FACTORY",
prefix: () => h(NButton, { text: true, type: "primary" }, { default: () => "FACTORY" }),
children: [
{
label: "id", key: "id",
suffix: () => h(NButton, { text: true, type: "primary" }, { default: () => "marco" }),
},
{
label: "groove", key: "groove",
children: [
{
label: "shape", key: "shape",
suffix: () => h( NButton, { text: true, type: "primary" }, { default: () => "box" } ),
},
],
}
],
},
]"
填充 naive-ui> naive-ui ntree 组件。 Naive-UI组件需要 treeoption [] 类型才能正常运行。
export interface TreeOptionBase {
key?: Key;
label?: string;
checkboxDisabled?: boolean;
disabled?: boolean;
isLeaf?: boolean;
children?: TreeOption[];
prefix?: () => VNodeChild;
suffix?: () => VNodeChild;
}
export declare type TreeOption = TreeOptionBase & {
[k: string]: unknown;
};
如何将我的生成的字符串转换为 treeoption [] 类型?
提前致谢
I have this string returned by an automated system.
"[
{
key: "FACTORY",
prefix: () => h(NButton, { text: true, type: "primary" }, { default: () => "FACTORY" }),
children: [
{
label: "id", key: "id",
suffix: () => h(NButton, { text: true, type: "primary" }, { default: () => "marco" }),
},
{
label: "groove", key: "groove",
children: [
{
label: "shape", key: "shape",
suffix: () => h( NButton, { text: true, type: "primary" }, { default: () => "box" } ),
},
],
}
],
},
]"
It is a javascript object good to populate the Naive-UI NTree component.
The Naive-UI component require a TreeOption[] type to run fine.
export interface TreeOptionBase {
key?: Key;
label?: string;
checkboxDisabled?: boolean;
disabled?: boolean;
isLeaf?: boolean;
children?: TreeOption[];
prefix?: () => VNodeChild;
suffix?: () => VNodeChild;
}
export declare type TreeOption = TreeOptionBase & {
[k: string]: unknown;
};
How to convert my generated string to TreeOption[] type ?
Thank's in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
json.parse
更改字符串
toarray
。You can try
JSON.parse
changeString
toArray
.