为了账号安全,请及时绑定邮箱和手机立即绑定

Go:使用 html/template 在新行上打印切片中的每个元素

Go:使用 html/template 在新行上打印切片中的每个元素

Go
叮当猫咪 2021-08-10 15:32:22
如何在新行上打印“apple”、“orange”和“pear”?去:const titlepage = `<html><h1>{{ .Title}}</h1><h1>{{ range $i := .Body}}{{$i}}{{end}}</h1></html>`type tp struct {    Title string    Body []string}func Read() ([]string) {    a := []string{"apple", "orange", "pear"}    return a}func main() {    as := tp{Title: "Hello", Body: Read()}    t := template.Must(template.New("Tele").Parse(titlepage))    t.Execute(os.Stdout, as)}电流输出:<html><h1>Hello</h1><h1>appleorangepear</h1></html>Go Playground 上的代码:http : //play.golang.org/p/yhyfcq--MM
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 274 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号