如何以数组形式访问JavaScript对象

时间:2019-06-26 14:08:59

标签: javascript node.js go gopherjs

在GopherJS中,对象的成员本身就是对象(就像js处理内部事务一样,ttbomk)。

因此,在访问成员时,会返回一个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

传入的{ RID: [ 136, 210, 92, 97, 152, 26, 17, 233, 147, 147, 8, 0, 39, 223, 163, 7 ],是从服务器的JSON响应中提取的js对象。其成员“ RID”是字节值的数组-例如[]interface{} ...

我没有在gopherjs的js文档中看到任何关于如何从* js.Object转换为等效于js数组的gopherjs(即*js.Object -> []interface{}

的清晰指示)的信息

想法?

zoo (ssdlite_mobilenet_v2_coco)

1 个答案:

答案 0 :(得分:1)

呜呜-知道了! 感谢您的建议:)

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!
}