亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎樣才能使結構進入其中包含對象數組的對象?

我怎樣才能使結構進入其中包含對象數組的對象?

Go
白豬掌柜的 2022-06-27 16:35:24
我在前端使用 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"`

}


查看完整回答
反對 回復 2022-06-27
  • 1 回答
  • 0 關注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號