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

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

vue2 動態的復選列表里怎么綁定對象數組

vue2 動態的復選列表里怎么綁定對象數組

夢里花落0921 2018-10-09 17:18:34
需求大致是: 由后臺查詢出單據里選擇的省市列表, 然后填寫對應省市的產品數量. 把勾選的數據提交到后臺.html<ul><li v-for="option in options">    <input type="checkbox" v-model="selected" v-bind:value="option.id">    <span>{{option.text}}</span>    <input name="num" type="number" placeholder="填寫數量" /></li></ul>預覽jsnew Vue({  el: 'body',  data: {    selected: [],    options: [       { text: '上海市', id: '20' },       { text: '湖北省', id: '43' },       { text: '河南省', id: '45' },       { text: '北京市', id: '10' }     ]// 選項是動態加載出來的, 數量不定   } });需要把勾選了的選項和后面的數量組成對象數組提交到后臺.需要的數據格式為:selected:[{     id:10,// 省市id     num:24// 數量 }]這樣的應該怎么做?
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

 <ul>
            <li v-for="option in options">
               <input type="checkbox" v-model="selected" v-bind:value="option">
               <span>{{option.text}}</span>
               <input name="num" type="number" v-model="option.num" />
            </li>
        </ul>
       <div v-for="item in selected">
           {{item}}      </div>

new Vue({  el: 'body',  data: {    selected: [],    options: [
        { text: '上海市', id: '20',num:'' },
        { text: '湖北省', id: '43',num:'' },
        { text: '河南省', id: '45',num:'' },
        { text: '北京市', id: '10',num:'' }
    ]
  }
});


查看完整回答
反對 回復 2018-11-16
  • 1 回答
  • 0 關注
  • 980 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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