第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

每個value的值不同實現(xiàn)了,但是不知道怎么傳給后臺同樣多的對象,我是這樣實現(xiàn)的

每個value的值不同實現(xiàn)了,但是不知道怎么傳給后臺同樣多的對象,我是這樣實現(xiàn)的

蕪湖不蕪 2019-03-05 21:27:09
<table border="1" v-for="(item,i) in newList">    <tr>        <td colspan="3">{{item.deviceName}}</td>    </tr>    <tr v-for="(x,y) in item.list">        <td>{{x.unitName}}</td>        <td>{{x.itemName}}</td>        <td v-show="x.itemType==2">            <button class="btn" @click="zhengchang(item,i,x,y)">正常</button>            <button class="btn" @click="yichang(item,i,x,y)">異常</button>            <!--<button class="btn" @click="beizhu(x)">備注</button>-->        </td>        <td v-show="x.itemType==1">            <input type="text" v-model="wen.two" @click="inputbeizhu(item,i,x,y)" />        </td>    </tr></table>我是按著固定的下標(biāo)加的,使用說不會重復(fù),zhengchang(item, i, x, y) {    //            console.log(item);//每一個    //            console.log(i);//每一個的下標(biāo)    //            console.log(x);//當(dāng)前的item    //            console.log(y);//當(dāng)前的下標(biāo)    //            console.log(y);    this.wen.three = 0;    this.newList[i].list[y].value = this.wen.three;//當(dāng)前的對象    console.log(this.newList[i].list[y].value = this.wen.three);    console.log(this.newList[i].list)}點擊異常的時候yichang(item, i, x, y) {    //            let i=i;    console.log(item);//每一個    console.log(i);//每一個的下標(biāo)    console.log(x);//當(dāng)前的item    console.log(y);//當(dāng)前的下標(biāo)    this.wen.three = 1;    this.newList[i].list[y].value = this.wen.three;//當(dāng)前的對象    console.log(this.newList);}點擊橫線的時候inputbeizhu(item, i, x, y) {    let _this = this;    //            alert(11)    //            console.log(item);//每一個    //            console.log(i);//每一個的下標(biāo)    //            console.log(x);//當(dāng)前的item    //            console.log(y);//當(dāng)前的下標(biāo)    MessageBox.prompt('請輸入值').then(({ value, action }) => {        console.log(value)        _this.wen.two = value;        _this.newList[i].list[y].value = _this.wen.two;        console.log(_this.newList[i].list[y].value);    });}后臺要的格式是這樣的arr:[    {itemId:1,value:1},    {itemId:1,value:"文字"},    {itemId:1,value:2}]    填寫完點擊確定的時候我的json格式變?yōu)閣 我先怎么才能把格式寫成后臺需要的,而且生成和當(dāng)前我的數(shù)組一樣多的對象呢?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗 獲得超11個贊

看樣子是 Vue,在每一步操作的時候,實際都是修改了 newList 的內(nèi)容,然后我猜你只需要把 newList 丟給后臺就可以了。不過你似乎要先把 newList 中的 deviceId 和 deviceName 合并到 list 中的每一項里去……,可以通過 map 和 reduce 生成一個新的數(shù)組出來。


給你個示例


const data = [

    {

        deviceId: 0,

        deviceName: "0000",

        list: [

            {

                areaId: 1

            },

            {

                areaId: 2

            }

        ]

    },

    {

        deviceId: 1,

        deviceName: "0001",

        list: [

            {

                areaId: 3

            }

        ]

    }

];


const all = data.reduce((all, group) => {

    const list = group.list

        .map(m => ({

            ...m,

            deviceId: group.deviceId,

            deviceName: group.deviceName

        }));

    all.push(...list);

    return all;

}, []);


console.log(all);

結(jié)果


[ { areaId: 1, deviceId: 0, deviceName: '0000' },

  { areaId: 2, deviceId: 0, deviceName: '0000' },

  { areaId: 3, deviceId: 1, deviceName: '0001' } ]


查看完整回答
反對 回復(fù) 2019-03-15
  • 1 回答
  • 0 關(guān)注
  • 426 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號