dswqw66280 2016-05-27 20:06
浏览 46
已采纳

将嵌套结构中的切片传递到Go中的Revel模板中

I'm trying to pass off slices in a nested struct to a Revel template, but I get the error:

7: executing "App/Index.html" at <.data.company>: company is an unexported field of struct type interface {}

CONTROLLER
type company struct {
    Tradetotals float64
    Totals      float64
    CostCount   string
    TraderCount string
}

type alldata struct {
    company []company
}



func (c App) Index() revel.Result {
    //etc
    //etc
    //etc

    return c.Render(data)
}

INDEX
{{range $count, $company := .data.company}}
    <div>
    <button type="submit" class="btn btn-sq-lg btn-danger" name="333" value="2-50000">
            <i class="fa fa-user fa-5x"></i><br/>
            Demo Danger <br>Button
    </button>

          <button type="submit" class="btn btn-sq-lg btn-success">
            <i class="fa fa-user fa-5x"></i>
            US: {{$company.Tradetotals}}<br>{{$company.Totals}}<br>{{$company.Totals}} {{$company.CostCount}}

    </button>
    </div>
{{end}}

Does anyone know how to accomplish this? Any help would be appreciated! Thank you.

  • 写回答

1条回答 默认 最新

  • douzhang1299 2016-05-27 20:46
    关注

    There is a problem in your struct. When executing a template, you only have access to the exported fields of your structs.

    If you try to access an unexported one, you'll receive an error. It should solve your issue.

    type alldata struct {
        Company []company
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助