Go 将Elm与现有web应用程序服务集成的正确方法

Go 将Elm与现有web应用程序服务集成的正确方法,go,elm,Go,Elm,我有一个我在Golang中编写的后端服务,类似这样: func PageA_RequestHandler(ctx *W.Context) { // init things if is_ajax { // handle the API request, render the JSON return } // query the initial rows values := M.SX{ `rows`: model1.GetRows(10), `co

我有一个我在
Golang
中编写的后端服务,类似这样:

func PageA_RequestHandler(ctx *W.Context) {
  // init things
  if is_ajax {
    // handle the API request, render the JSON
    return
  }
  // query the initial rows
  values := M.SX{
    `rows`: model1.GetRows(10),
    `columns`: model1.GetColumns(),
  }
  // render the html
  ctx.Render(`page_a_template`,values)
}
<div id="grid"></div>
<script>
  var rows = {/* rows */};
  var cols = [/* columns */]
  new GridBuilder('grid',cols,rows);
</script>
main =
    Html.programWithFlags
        { init = init, ... }
然后文件
page\u a\u template.html
(在第一次呈现时加载并缓存)是一个html文件,其内容如下:

func PageA_RequestHandler(ctx *W.Context) {
  // init things
  if is_ajax {
    // handle the API request, render the JSON
    return
  }
  // query the initial rows
  values := M.SX{
    `rows`: model1.GetRows(10),
    `columns`: model1.GetColumns(),
  }
  // render the html
  ctx.Render(`page_a_template`,values)
}
<div id="grid"></div>
<script>
  var rows = {/* rows */};
  var cols = [/* columns */]
  new GridBuilder('grid',cols,rows);
</script>
main =
    Html.programWithFlags
        { init = init, ... }

变量行={/*行*/};
var cols=[/*列*/]
新的网格生成器(“网格”、列、行);
在哪里:

{/*行*/}
[/*列*/]
是我的javascript友好模板语法,还有一些其他语法,如:
/*!条形码*/
{yay}

newgridbuilder
是我的自定义javascript组件,它创建类似于
datatables.net
editablegrid.net

问题是,如果我使用
Elm
,将
{/*rows*/}
注入已编译html的正确方法是什么?

使用(假设您的主模块名为
App
):

您的
main
函数如下所示:

func PageA_RequestHandler(ctx *W.Context) {
  // init things
  if is_ajax {
    // handle the API request, render the JSON
    return
  }
  // query the initial rows
  values := M.SX{
    `rows`: model1.GetRows(10),
    `columns`: model1.GetColumns(),
  }
  // render the html
  ctx.Render(`page_a_template`,values)
}
<div id="grid"></div>
<script>
  var rows = {/* rows */};
  var cols = [/* columns */]
  new GridBuilder('grid',cols,rows);
</script>
main =
    Html.programWithFlags
        { init = init, ... }
我强烈建议您阅读本节的内容。它解释了带有标志的
程序以及从JavaScript接收/向JavaScript发送数据的其他方法