增加生成新节点的方法
This commit is contained in:
@ -7,11 +7,62 @@
|
||||
// Date : 2023-03-28 18:42
|
||||
package tree
|
||||
|
||||
import "strings"
|
||||
|
||||
// New 生成一棵JSON树
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:42 2023/3/28
|
||||
func New(jsonData string) *Node {
|
||||
return nil
|
||||
func New(jsonData string) *Generate {
|
||||
jsonData = strings.TrimSpace(jsonData)
|
||||
g := &Generate{
|
||||
jsonData: jsonData,
|
||||
}
|
||||
if g.isArray() {
|
||||
g.root = &Node{
|
||||
IsVirtual: true,
|
||||
Value: nil,
|
||||
ValueType: "",
|
||||
Key: "",
|
||||
Show: false,
|
||||
ShowKey: "",
|
||||
AllowEdit: false,
|
||||
AllowChangeType: false,
|
||||
DefaultValue: nil,
|
||||
ParentNode: nil,
|
||||
PreBrotherNode: nil,
|
||||
LastBrotherNode: nil,
|
||||
SonNodeList: nil,
|
||||
}
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
// Generate ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:46 2023/3/28
|
||||
type Generate struct {
|
||||
root *Node
|
||||
jsonData string
|
||||
}
|
||||
|
||||
// isObject 整体是否为对象
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:51 2023/3/28
|
||||
func (g *Generate) isObject() bool {
|
||||
return strings.HasPrefix(g.jsonData, KeywordObjectStart)
|
||||
}
|
||||
|
||||
// isArray 整体是否为数组
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:51 2023/3/28
|
||||
func (g *Generate) isArray() bool {
|
||||
return strings.HasPrefix(g.jsonData, KeywordArrayStart)
|
||||
}
|
||||
|
Reference in New Issue
Block a user