提交 3ffa8e30 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

get mod arr for child fields scroll

上级 32337e60
......@@ -7,3 +7,4 @@
/data/custom/
/conf/
/demo/default.yaml
/test/
......@@ -5,11 +5,11 @@ version: 1.0
fields:
- field: test1
range: [1-9]:3{2}
range: [1-5]:3{2}
postfix: "\t"
- field: test2
range: Z-A:R{2}
range: Z-P:R{2}
postfix: "\t"
- field: test3
......@@ -25,3 +25,15 @@ fields:
loop: 2-9
loopfix: "|"
postfix: "\t"
- field: field6
fields:
- field: child1
range: a-z
prefix: part1_
postfix: '|'
- field: child2
range: 1-9
prefix: part2_
postfix: '|'
......@@ -58,22 +58,13 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
values := make([]string, 0)
if len(field.Fields) > 0 { // sub fields
arr := make([][]string, 0) // 2 dimension arr for child, [ [a,b,c], [1,2,3] ]
arrOfArr := make([][]string, 0) // 2 dimension arr for child, [ [a,b,c], [1,2,3] ]
for _, child := range field.Fields {
childValues := GenerateForField(&child, total, withFix)
arr = append(arr, childValues)
arrOfArr = append(arrOfArr, childValues)
}
for i := 0; i < total; i++ {
concat := ""
for _, row := range arr {
concat = concat + row[i] // get one item from each child, grouped as a1 or b2
}
// should be done by calling LoopSubFields func as below, so disable this line
//concat = field.Prefix + concat + field.Postfix
values = append(values, concat)
}
connectChildrenToSingleStr(arrOfArr, total, &values)
values = LoopSubFields(field, values, total, true)
} else if field.From != "" { // refer to res
......@@ -264,4 +255,37 @@ func computerLoop(field *model.DefField) {
}
(*field).LoopIndex = (*field).LoopStart
}
\ No newline at end of file
}
func connectChildrenToSingleStr(arrOfArr [][]string, total int, values *[]string) {
indexArr := getModArr(arrOfArr)
for i := 0; i < total; i++ {
concat := ""
for idx, row := range arrOfArr {
concat = concat + row[indexArr[idx]] // get one item from each child, grouped as a1 or b2
}
*values = append(*values, concat)
}
}
func getModArr(arrOfArr [][]string) []int {
indexArr := make([]int, 0)
for _, _ = range arrOfArr {
indexArr = append(indexArr, 0)
}
for i := 0; i < len(arrOfArr); i++ {
loop := 1
for j := i + 1; j < len(arrOfArr); j++ {
loop = loop * len(arrOfArr[j])
}
indexArr[i] = loop
}
return indexArr
}
......@@ -23,6 +23,7 @@ var (
WithHead bool
HeadSep string
Trim bool
Recursive bool
JsonResp string = "[]"
Ip string
......
......@@ -105,6 +105,9 @@ func main() {
flagSet.BoolVar(&vari.Trim, "T", false, "")
flagSet.BoolVar(&vari.Trim, "trim", false, "")
flagSet.BoolVar(&vari.Recursive, "r", false, "")
flagSet.BoolVar(&vari.Recursive, "recursive", false, "")
flagSet.BoolVar(&example, "e", false, "")
flagSet.BoolVar(&example, "example", false, "")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册