1 回答

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
您需要append從切片的結(jié)果GetCommPlans,commPlans現(xiàn)在您正在覆蓋任何以前返回的結(jié)果。
要么做:
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
}
或者:
comms := models.GetComms(CommID)
if comms == nil {
componentsJson.WriteError(ctx, componentsError.ERROR_PARAMETERS_INVALID)
return
}
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
}
- 1 回答
- 0 關(guān)注
- 175 瀏覽
添加回答
舉報(bào)