呈现 html 个模板 golang 狂欢
rendering html templates golang revel
我希望有人能够帮助我。我已经开始构建一个网络应用程序,并决定使用 GO 和 Revel。到目前为止,我已经学到了很多东西,但是有一个功能我似乎无法使用。我有以下代码:
package controllers
import (
"github.com/revel/revel"
_ "github.com/denisenkom/go-mssqldb"
"database/sql")
type App struct {
*revel.Controller
}
type resultRow struct {
TransactionDomain string
TransactionType string
TransactionIsoResponse string
Store string
Terminal string
Vendor string
RequestDT string
ResponseDT string
AccountDisplay string
AccountDetails1 string
InvoiceNumber string
Amount string
}
type colNames struct {
Name string
}
type resultTable struct {
fpk string
columns []colNames
resultRows []resultRow
}
func (c App) FpkTable() revel.Result {
//all db section goes here. I have confirmed the results are obtaind back
//from the db.
err = rows.Scan(&resRow.TransactionDomain,
&resRow.TransactionType,
&resRow.TransactionIsoResponse,
&resRow.Store,
&resRow.Terminal,
&resRow.Vendor,
&resRow.RequestDT,
&resRow.ResponseDT,
&resRow.AccountDisplay,
&resRow.AccountDetails1,
&resRow.InvoiceNumber,
&resRow.Amount)
if err != nil {
revel.INFO.Println("Scan failed:", err.Error())
}
arrRow = append(arrRow, resRow)
}
columnNames := []colNames{{Name:"Domain"}, {Name:"Type"}, {Name:"Vendor Response"}, {Name:"Store"}, {Name:"Register"},
{Name:"Request DT"}, {Name:"Response DT"}, {Name:"Account"}, {Name:"Token"}, {Name:"Invoice"}, {Name:"Amount"}}
table := &resultTable{c.Request.FormValue("store") + "-" + c.Request.FormValue("register") + "-" + c.Request.FormValue("invoice") + "-" + c.Request.FormValue("date"), columnNames, arrRow}
return c.Render(table)
我有以下 html 模板:
<div class="row">
<a>{{.fpk}}</a>
<ul>
{{range .columns}}
<li>{{.Name}}</li>
{{end}}
</ul>
</div>
我期待看到这样的东西
<div class="row">
<a>AAA-BBB-CCC-DDD</a>
<ul>
<li>Domain</li>
<li>Type</li>
.
.
.
</ul>
</div>
但是我没有在
处将任何值传递到模板中
<div class="row">
<a></a>
<ul>
</ul>
::after
//This line makes me believe the processing of the
//template is being done properly except the data
//is not being passed properly to the template.
</div>
我浏览了所有可能的网站,对此感到疑惑,但一直未能找到解决方案。
我相信这会很简单,但无论如何,感谢您提供的任何帮助。
我不确定你的模板语法,通常我会这样做:
<div class="row">
<a>{{.fpk}}</a>
<ul>
{{range $index, $element := .columns}}
<li>{{$element.Name}}</li>
{{end}}
</ul>
</div>
我能想到的另一件事是您的数据可能为空,您是否尝试检查列结构字段以查看它是否包含数据?
我希望有人能够帮助我。我已经开始构建一个网络应用程序,并决定使用 GO 和 Revel。到目前为止,我已经学到了很多东西,但是有一个功能我似乎无法使用。我有以下代码:
package controllers
import (
"github.com/revel/revel"
_ "github.com/denisenkom/go-mssqldb"
"database/sql")
type App struct {
*revel.Controller
}
type resultRow struct {
TransactionDomain string
TransactionType string
TransactionIsoResponse string
Store string
Terminal string
Vendor string
RequestDT string
ResponseDT string
AccountDisplay string
AccountDetails1 string
InvoiceNumber string
Amount string
}
type colNames struct {
Name string
}
type resultTable struct {
fpk string
columns []colNames
resultRows []resultRow
}
func (c App) FpkTable() revel.Result {
//all db section goes here. I have confirmed the results are obtaind back
//from the db.
err = rows.Scan(&resRow.TransactionDomain,
&resRow.TransactionType,
&resRow.TransactionIsoResponse,
&resRow.Store,
&resRow.Terminal,
&resRow.Vendor,
&resRow.RequestDT,
&resRow.ResponseDT,
&resRow.AccountDisplay,
&resRow.AccountDetails1,
&resRow.InvoiceNumber,
&resRow.Amount)
if err != nil {
revel.INFO.Println("Scan failed:", err.Error())
}
arrRow = append(arrRow, resRow)
}
columnNames := []colNames{{Name:"Domain"}, {Name:"Type"}, {Name:"Vendor Response"}, {Name:"Store"}, {Name:"Register"},
{Name:"Request DT"}, {Name:"Response DT"}, {Name:"Account"}, {Name:"Token"}, {Name:"Invoice"}, {Name:"Amount"}}
table := &resultTable{c.Request.FormValue("store") + "-" + c.Request.FormValue("register") + "-" + c.Request.FormValue("invoice") + "-" + c.Request.FormValue("date"), columnNames, arrRow}
return c.Render(table)
我有以下 html 模板:
<div class="row">
<a>{{.fpk}}</a>
<ul>
{{range .columns}}
<li>{{.Name}}</li>
{{end}}
</ul>
</div>
我期待看到这样的东西
<div class="row">
<a>AAA-BBB-CCC-DDD</a>
<ul>
<li>Domain</li>
<li>Type</li>
.
.
.
</ul>
</div>
但是我没有在
处将任何值传递到模板中 <div class="row">
<a></a>
<ul>
</ul>
::after
//This line makes me believe the processing of the
//template is being done properly except the data
//is not being passed properly to the template.
</div>
我浏览了所有可能的网站,对此感到疑惑,但一直未能找到解决方案。
我相信这会很简单,但无论如何,感谢您提供的任何帮助。
我不确定你的模板语法,通常我会这样做:
<div class="row">
<a>{{.fpk}}</a>
<ul>
{{range $index, $element := .columns}}
<li>{{$element.Name}}</li>
{{end}}
</ul>
</div>
我能想到的另一件事是您的数据可能为空,您是否尝试检查列结构字段以查看它是否包含数据?