在GopherJS中,对象的成员本身就是对象(就像js在幕后处理事情一样)。
因此,当访问成员时,会返回一个*js.Object
func makeRID(o *js.Object) string {
// access the array of numbers in member RID:
arr := o.Get("RID")
// arr is now a *js.Object - not an []interface{} - which is what I actually need (and what the contents of the property RID really are...
}传入的o是从服务器的JSON响应中提取的js对象。它的成员"RID“是字节值的数组-例如{ RID: [ 136, 210, 92, 97, 152, 26, 17, 233, 147, 147, 8, 0, 39, 223, 163, 7 ], ...
我没有在谷歌上搜索,也没有在gopherjs的js文档中看到任何明确的指示,说明如何从*js.Object转到与js数组等效的gopherjs,即[]interface{}
想法?
*js.Object -> []interface{}
发布于 2019-06-26 22:55:15
哇-呼-明白了!感谢您的建议:)
func makeRID(o *js.Object) string {
// access the array of numbers in member RID:
jsRID := o.Get("RID")
// I know that the source object's RID member is an Array, so we can access it in gopherjs as:
jsArray := jsRID.Interface().([]interface{})
// ... profit!
}https://stackoverflow.com/questions/56774821
复制相似问题