WebSharper 界面生成器 - 记录

发布于 2024-12-06 05:09:39 字数 258 浏览 0 评论 0原文

我如何定义一条将被序列化为 JSON 对象的记录...我一直在尝试为 YUI2 构造函数构建 oConfig 参数,例如:

type TreeParameter =
    {
        Type : string
        Label : string
        Expanded : bool
        Children : TreeParameter array
    }

谢谢!

大卫

How do I go about defining a record that would be serialized to a JSON object... I've been trying to build the oConfig parameter for YUI2 constructor, something like:

type TreeParameter =
    {
        Type : string
        Label : string
        Expanded : bool
        Children : TreeParameter array
    }

Thanks!

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天邊彩虹 2024-12-13 05:09:39

我想我们可以实现这个,但它还没有进入接口生成器。现在您可以执行以下操作:

let TreeParameter =
    let self = Type.New()
    Pattern.Config "TreeParameter" {
        Required =
            [
                "Type", T<string>
                "Label", T<string>
                "Expanded", T<bool>
                "Children", Type.ArrayOf self
            ]
        Optional = []
    }
    |=> self

从 F# 的角度来看,生成的类型将如下所示:

type TreeParameter(t: string, l: string, e: bool, c: TreeParameter[]) =
    member this.Type = t
    member this.Label = l
    member this.Expanded = e
    member this.Children = c

从 JavaScript 的角度来看,值将如下所示:

{Type:t,Label:l,Expanded:e,Children:c}

本质上,它就像一条记录,但没有记录语法和功能扩展的优势。

I guess we could implement this but it has not yet made it into the interface generator. For now you can do:

let TreeParameter =
    let self = Type.New()
    Pattern.Config "TreeParameter" {
        Required =
            [
                "Type", T<string>
                "Label", T<string>
                "Expanded", T<bool>
                "Children", Type.ArrayOf self
            ]
        Optional = []
    }
    |=> self

From F# point of view the generated type will look like this:

type TreeParameter(t: string, l: string, e: bool, c: TreeParameter[]) =
    member this.Type = t
    member this.Label = l
    member this.Expanded = e
    member this.Children = c

From JavaScript perspective, the values would look like this:

{Type:t,Label:l,Expanded:e,Children:c}

In essence it is like a record without the benefit of record syntax and functional extension.

苦妄 2024-12-13 05:09:39

WebSharper 现在已经实现了这个功能。只需使用TSelf

例子:

let TreeParameter =
    Pattern.Config "TreeParameter" {
        Required =
            [
                "Type", T<string>
                "Label", T<string>
                "Expanded", T<bool>
                "Children", Type.ArrayOf TSelf
            ]
        Optional = []
    }

WebSharper has now implemented this feature. Just use TSelf.

Example:

let TreeParameter =
    Pattern.Config "TreeParameter" {
        Required =
            [
                "Type", T<string>
                "Label", T<string>
                "Expanded", T<bool>
                "Children", Type.ArrayOf TSelf
            ]
        Optional = []
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文