feat:完善项目信息
This commit is contained in:
@ -29,3 +29,56 @@ func TestArrayStrings(t *testing.T) {
|
||||
t.Log(b)
|
||||
t.Log(reflect.TypeOf(b).String())
|
||||
}
|
||||
|
||||
type Tree struct {
|
||||
ID uint64 `json:"id"`
|
||||
Checked bool `json:"checked"`
|
||||
Children []*Tree `json:"children"`
|
||||
}
|
||||
|
||||
func show(src []*Tree, parent *Tree) {
|
||||
for _, v := range src {
|
||||
if !v.Checked && parent != nil {
|
||||
parent.Checked = false
|
||||
}
|
||||
if len(v.Children) > 0 {
|
||||
show(v.Children, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func input(src []*Tree, out map[uint64]uint64) {
|
||||
for _, v := range src {
|
||||
out[v.ID] = v.ID
|
||||
|
||||
if len(v.Children) > 0 {
|
||||
input(v.Children, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInArray(t *testing.T) {
|
||||
src := []*Tree{
|
||||
&Tree{
|
||||
ID: 1,
|
||||
Checked: false,
|
||||
Children: []*Tree{
|
||||
&Tree{
|
||||
ID: 2,
|
||||
Checked: true,
|
||||
Children: nil,
|
||||
},
|
||||
&Tree{
|
||||
ID: 3,
|
||||
Checked: false,
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
out := make(map[uint64]uint64, 0)
|
||||
input(src, out)
|
||||
|
||||
//show(out, nil)
|
||||
t.Log(AnyToJSON(out))
|
||||
}
|
||||
|
Reference in New Issue
Block a user