我正在阅读Cordova教程并尝试在GopherJS中进行练习。我安装了"设备"插件(cordova plugin add cordova-plugin-device
)并尝试获取设备的字段:
type (
Info struct {
*js.Object
Cordova string `js:"cordova"`
Model string `js:"model"`
Platform string `js:"platform"`
Serial string `js:"serial"`
UUID string `js:"uuid"`
Version string `js:"version"`
}
)
var device = &Info{Object: js.Global.Get("device")}
但他们是空的。我怎么读它们?
有没有办法让GopherJS填充*js.Object
?
答案 0 :(得分:0)
我明白了。我需要等到deviceready
事件发生:
var device *Info
// ...
func onDeviceReady(dom.Event) {
device = &Info{Object: js.Global.Get("device")}
}