折雨的天空
golang中像php一样,给结果集增加字段
2019-8-3 我好笨


定义结构体



type sortSons struct {
models.Sort
Sons int
}

查询数据,并通过range赋值



userList,_:=models.QuerySortList(&listsearch,(page-1)*pre_page,pre_page)
var attrs = map[int]interface{}{}
for i,v:=range userList{
sonSearch:=models.ListSearch{ParentId:int(v.ID)}
childrenCount,_:=models.QuerySortListCount(&sonSearch)
attrs[i]=sortSons{Sort:*v,Sons:childrenCount}
}

主要实现是在attrs这句,其中Sort后面要用*。



目前的能力,不考虑效率,只考虑功能实现。

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容