【发布时间】:2018-02-23 13:54:14
【问题描述】:
作为学习的一部分,我尝试了以下代码 sn-ps。
func ASNGroup(asn []map[string]interface{}) bool {
eachgroup := make([][]map[string]interface{}, 0)
for i := range asn {
for _, v := range asn[i] {
// How to filter the based on Key based on the below filter i should group the above asn array maps.
asn[i]["ID"]
}
}
fmt.Println(eachgroup)
return true
}
请帮助我编写代码,是的,我避免使用 struct,因为我正在根据上传的 xlsx 表准备 asn 对象。是的,我知道这是强制密钥,因此我可以硬编码此密钥以进行过滤。我知道它不像javascript那么容易。对于编写函数,我知道应该有一些返回初始化,我初始化了 dummy bool 以避免错误。
请不要偏离问题,提出建议
理解并请帮助在逻辑上将这样的 [[],[]] 分组。
这是 []map[string]interface{}
的以下示例 [{"id":"1","seperator":"B","code":"twenty1"},
{"id":"2","seperator":"A","code":"twenty2"},
{"id":"3","seperator":"B","code":"twenty3"}]
分隔符是对象内部分隔对象的关键。
{"B" : [{"id":"1","seperator":"B","code":"twenty1"},
{"id":"3","seperator":"B","code":"twenty3"}]
, "A" : [{"id":"2","seperator":"A","code":"twenty2"}]}
【问题讨论】:
-
你能举一个你想要的输出的例子吗?
-
当然@maerics,我正在更新上述问题本身。请检查一下。