如何定义将序列化为JSON对象的记录...我一直在尝试为YUI2构造函数构建oConfig参数,如:
type TreeParameter =
{
Type : string
Label : string
Expanded : bool
Children : TreeParameter array
}
谢谢!
大卫
答案 0 :(得分:1)
我想我们可以实现这个,但它还没有进入接口生成器。现在你可以这样做:
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}
从本质上讲,它就像一个没有记录语法和功能扩展的记录。
答案 1 :(得分:1)
WebSharper现已实现此功能。只需使用TSelf
。
示例:
let TreeParameter =
Pattern.Config "TreeParameter" {
Required =
[
"Type", T<string>
"Label", T<string>
"Expanded", T<bool>
"Children", Type.ArrayOf TSelf
]
Optional = []
}