/* * @description: 视图层 文件夹 models * @Author: CP * @Date: 2020-09-11 15:12:43 * @FilePath: \construction_management\web\viewmodels\tree.go */ package viewmodels import ( validation "github.com/go-ozzo/ozzo-validation/v3" ) type Tree struct { Id string `form:"id" json:"id"` Name string `form:"name" json:"name"` ProjectId string `form:"projectId"` TenderId int `form:"tenderId"` ParentId string `form:"parentId" json:"parentId"` Depth int `form:"depth"` Serial string `form:"serial"` Attribution string `form:"attribution"` Isfolder int `form:"isfolder"` CreateTime string `form:"createTime"` UpdateTime string `form:"updateTime"` MoveId string `form:"moveId"` Csrf string `form:"csrf"` Leaf bool `json:"leaf"` Children []*Tree `json:"children"` } func (l Tree) Validate() error { return validation.ValidateStruct(&l, validation.Field(&l.Name, validation.Required.Error("文件夹名称不能为空"), validation.Length(1, 60).Error("最多 15 个字符")), ) } // func (l Tree) Maketree(Data []*Tree, node *Tree) { //参数为父节点,添加父节点的子节点指针切片 // childs, _ := this.Havechild(Data, node) //判断节点是否有子节点并返回 // if childs != nil { // // fmt.Printf("\n") // // fmt.Println(*node) // // fmt.Println("子节点:") // for _, v := range childs { // fmt.Println(*v) // } //打印 // node.Child = append(node.Child, childs[0:]...) //添加子节点 // for _, v := range childs { //查询子节点的子节点,并添加到子节点 // _, has := Havechild(Data, v) // if has { // Maketree(Data, v) //递归添加节点 // } // } // } // } // func (l Tree) Havechild(Data []*Tree, node *Tree) (child []*Tree, yes bool) { // for _, v := range Data { // if v.ParentId == node.Id { // child = append(child, v) // } // } // if child != nil { // yes = true // } // return // } // func transformjson(Data *Tree) { //转为json // Jsondata, _ := json.Marshal(Data) // fmt.Println(string(Jsondata)) // }