Skip to content

Integration with external JS lib #1063

@marosiak

Description

@marosiak

Hi, I love this idea of creating frontend with Go, I've started making my side-project with go-app, and had no issues, untill..

I need to embed charts - my idea is to not reinvent wheel, so I had idea of using popular JS lib for charts - but then I've found that someone made binding for another lib in Go - It's great, because it gives me Html output

So far everything was cool, I had idea to extract html, then embed it into go-app with app.Raw(hereIsHtmlString)

TL;DR

I'd love to perform JS actions thru go-app, so I can use JS chart libs

Problem 1:

  • app.Raw() seems to ignore <script> and <style>

And I don't mean main script - because I've attached it to app.Handler same as any other script (tailwind for example), but this script which is being loaded is manipulating chart

<script type="text/javascript">
    "use strict";
    let goecharts_RzqGdVyyqgiS = echarts.init(document.getElementById('RzqGdVyyqgiS'), "white", { renderer: "canvas" });
    let option_RzqGdVyyqgiS = {"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{},"series":[{"name":"Category A","type":"bar","data":[{"value":6},{"value":208},{"value":260},{"value":271},{"value":176},{"value":103},{"value":23}],"label":{}}],"title":{"text":"Chart"},"toolbox":{},"tooltip":{},"xAxis":[{"data":["A","B","C","D","E","F","G"]}],"yAxis":[{}]}

    goecharts_RzqGdVyyqgiS.setOption(option_RzqGdVyyqgiS);
</script>

Problem 2:

Even if I'd find any way to include this dynamically created script into my component, can I really relay that the HTML container will exist before execution of this script?

Solution?

It'd be great if I could call JS functions directly from go-app, but I haven't found any way yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions