GopherJS和js / dom:所有goroutine都处于睡眠状态-死锁

时间:2018-09-20 15:03:46

标签: go gopherjs

我不确定这是怎么回事,但是我正在尝试使用js/dom库加载一些GopherJS代码。现在,我调用路由并收听服务器,然后加载脚本。这是错吗?

main.go:

package main

import (
    "app/controller"
    "app/script"
)

func main() {
    controller.Setup()
    script.LoadAll()
}

script.go:

package script

import (
    //"github.com/gopherjs/gopherjs/js"
    "honnef.co/go/js/dom"
)

func LoadAll() {
    d := dom.GetWindow().Document()

    toggle, slide, navbar, app := d.GetElementsByClassName("lv-navbar-expand")[0].(*dom.HTMLDivElement), d.GetElementsByClassName("lv-slive-nav")[0].(*dom.HTMLDivElement), d.GetElementsByClassName("navbar")[0].(*dom.HTMLDivElement), d.GetElementByID("app").(*dom.HTMLDivElement)

    toggle.AddEventListener("click", false, func(e dom.Event) {
        e.CurrentTarget().Class().Toggle("nav-expand-active")

        slide.Class().Toggle("lv-slide-nav-open")
        navbar.Class().Toggle("lv-slide-nav-is-open")
        app.Class().Toggle("lv-slide-nav-is-open")
    })
}

但是当我加载网站时,它会将其打印到控制台中

fatal error: all goroutines are asleep - deadlock!
$goroutine @ ..js:1498
$runScheduled @ ..js:1518
$schedule @ ..js:1534
$go @ ..js:1510
(anonymous) @ ..js:195352
(anonymous) @ ..js:195355

我在这里想念什么?

0 个答案:

没有答案