Mysql 如何使用另一个数组填充数组';戈朗的身份证
所以我想从COMM中的ID获取所有COMMPLAN,但出于某种原因,我只获取一个对象(这是COMM中的第一个ID)。 这是我的密码:Mysql 如何使用另一个数组填充数组';戈朗的身份证,mysql,arrays,go,go-gorm,Mysql,Arrays,Go,Go Gorm,所以我想从COMM中的ID获取所有COMMPLAN,但出于某种原因,我只获取一个对象(这是COMM中的第一个ID)。 这是我的密码: comms := models.GetComms(CommID) if comms == nil { componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID) return } var commPlans []models.CommPlan for _, co
comms := models.GetComms(CommID)
if comms == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
var commPlans []models.CommPlan
for _, comm := range comms {
commPlans = models.GetCommPlans(comm.CommPlanID)
}
if commPlans == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
您需要
将GetCommPlans
的结果追加到commPlans
切片中,现在您正在覆盖以前返回的任何结果
或者:
comms := models.GetComms(CommID)
if comms == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
// a slice of slices
var commPlans [][]models.CommPlan
for _, comm := range comms {
commPlans = append(commPlans, models.GetCommPlans(comm.CommPlanID))
}
if commPlans == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
或:
您需要将GetCommPlans
的结果追加到commPlans
切片中,现在您正在覆盖以前返回的任何结果
或者:
comms := models.GetComms(CommID)
if comms == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
// a slice of slices
var commPlans [][]models.CommPlan
for _, comm := range comms {
commPlans = append(commPlans, models.GetCommPlans(comm.CommPlanID))
}
if commPlans == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
或:
哦,我明白了……谢谢!哦,我明白了……谢谢!