1 回答

TA貢獻1831條經(jīng)驗 獲得超10個贊
在將值放入其中之前,您不需要分配地圖。
type CustomerManifest struct {
Customers []definitions.Customer
CustomersIndex map[int]map[int]definitions.Customer
}
func (m *CustomerManifest) AddCustomerDefinition(x, y int, customer definitions.Customer) {
// Get the existing map, if exists.
innerMap := m.CustomersIndex[x]
// If it doesn't exist, allocate it.
if innerMap == nil {
innerMap = make(map[int]definitions.Customer)
m.CustomersIndex[x] = innerMap
}
// Add the value to the inner map, which now exists.
innerMap[y] = customer
}
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報