Golang dynamic generation of headers and data

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The Golang struct does not support nested loops that are displayed on the interface, so it uses the map data structure to store the data. Look directly at the code and effects. Beego Framework Service-side code: '

func  (This *tablecontroller)  get ()  {    this. data["Thead"] = []string{"#",  "name",  "age"} //header data structure     this. data["Tbody"] = []string{"Id",  "Name",  "Age"} //corresponding field value      Personmap := make (map[string]string)     personmap["Id"] =  "1"      personmap["Name"] =  "Lisi"     personmap["Age"] =  "25 "    personmap1 := make (map[string]string)     personmap1[" Id "] = " 2 "    personmap1[" Name "] = " Zhangsan "     personmap1["Age"] =  "    person := make" (map[int64]map[string]string )     person[0] = personMap    person[1] =  Personmap1    fmt. PRINTLN (person)  &nbsP;  this. data["Person"] = person    this. tplnames =  "Table.tpl"}

' Front-end test code:



 


Final effect:

# Name Age

1 Lisi 25

2 Zhangsan 28

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.