go - 不能在go lang中将type []字符串用作类型字符串

标签 go lang

请帮助我如何解决此问题,我收到此错误

不能在附加中将Title1(类型[] c)用作类型[] string。

一旦我在这行上追加

文章=附加(文章,标题1)
谢谢

            type a struct {
                Title   []b
                Title1  []c
                Article [][]string
            }
            type b struct{
                DD   string
                FF int
            }
            type c struct{
                CC string
                EE string
            }
            type d struct{
                DD string
            }
            func main() {
                xx:=b{}
                Title:=[]b{}
                yy:=c{}
                Title1:=[]c{}
                Article:=[][]string{}
                for i:=0; i<=2; i++{
                    xx.DD=strconv.Itoa(i)+"a"
                    xx.FF=i
                    Title=append(Title,xx)
                    Title1=nil
                    for ii:=0; ii<=2; ii++{
                        yy.CC=strconv.Itoa(ii)+"b"
                        yy.EE=strconv.Itoa(ii)+"c"
                        Title1=append(Title1,yy)
                    }
                    fmt.Println(Title1)
                    Article=append(Article,Title1)  
                }
            var data = &a{
                    Title: Title,
                    Article: Article,
                }
                fmt.Println(data)
                tmpl := template.Must(template.New("test").Parse(tmplSrc))
                tmpl.Execute(os.Stdout, data)
            }

提前致谢

最佳答案

您正在尝试将Title1(类型[]c)追加到Article(类型[][]string)。

您只能将[]string类型的项目追加到Article。因此,您要么需要更改Article的类型,要么创建一个类型为TitleStr的新变量(例如[]string)。

关于go - 不能在go lang中将type []字符串用作类型字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50377630/

相关文章:

计算分数的Java程序

Solr 俄语拼写检查

jquery - 将声明的语言 append 到 html?

go - 检查我是否可以从 channel 读取

xml - 读取类型的属性 XMLName 属性值

linux - 捕获中断时抑制终端输出中的 '^C' 字符串

c++ - 类命名空间?

performance - go 中的 map vs switch 性能

go - 最小化 Go 中垃圾收集问题的最佳实践

jquery - 使用 jQuery 检测 html 语言