在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

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

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

<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)?/p>

clipboard.png

clipboard.png

w 我先怎么才能把格式寫成后臺需要的,而且生成和當(dāng)前我的數(shù)組一樣多的對象呢?

回答
編輯回答
赱丅呿

看樣子是 Vue,在每一步操作的時候,實際都是修改了 newList 的內(nèi)容,然后我猜你只需要把 newList 丟給后臺就可以了。不過你似乎要先把 newList 中的 deviceIddeviceName 合并到 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' } ]
2018年4月30日 03:35