我在前端使用 Vuejs,在后端使用 Go 語言。我的data變量具有以下格式的數據。var data = { software_type: this.$props.selected, selected_solutions: this.fromChildChecked, };通過console.log(data)在前端做,我得到以下輸出。在后端,我有這種格式的結構:type Technology struct { ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"` SoftwareType string `json:"software_type" bson:"software_type"` SelectedSolutions struct { selectedSolutions []string } `json:"selected_solutions" bson:"selected_solutions"`}我很確定我遇到的問題,這可能是由于我發送的數據格式和我制作的結構不同。我正在使用 MongoDB 作為數據庫。通過提交表單,數據以以下格式進入數據庫,這意味著,我得到一個空對象selected_solutions。{"_id":{"$oid":"5f5a1fa8885112e153b5a890"},"software_type":"Cross-channel Campain Mangment Software","selected_solutions":{}}這是我希望在 DB 上使用的格式或類似于下面的格式。{ "_id":{"$oid":"5f5a1fa8885112e153b5a890"}, "software_type":"Cross-channel Campain Mangment Software", "selected_solutions":{ Adobe Campaign: ["Business to Customer (B2C)", "Business to Business (B2B)"], Marin Software: ["E-Government", "M-Commerce"], }}如何更改 struct 以使其與我嘗試發送的數據兼容?預先感謝您的任何幫助。
1 回答

慕婉清6462132
TA貢獻1804條經驗 獲得超2個贊
根據您的數據庫結構,selected_solutions是一個包含字符串數組的對象:
type Technology struct {
ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
SoftwareType string `json:"software_type" bson:"software_type"`
SelectedSolutions map[string][]string `json:"selected_solutions" bson:"selected_solutions"`
}
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消