antd+vue3實現全選&反選


antd+vue3實現全選&反選

 


效果如下:

 

 

重要代碼如下:

 1      <a-form-item
 2           label="選擇研究院"
 4           v-bind="validateInfos.instituteIds"
 5         >
 6           <div style="margin-bottom: 10px">
 7             <a-space>
 8               <a-button size="small" type="primary" @click="onCheckAllInstitute(true)">
 9                 全選
10               </a-button>
11               <a-button size="small" @click="onCheckAllInstitute(false)">反選</a-button>
12             </a-space>
13           </div>
14           <a-checkbox-group v-model:value="modelRef.instituteIds">
15             <a-checkbox v-for="item in list" :key="item.instituteId" :value="item.instituteId">
16               {{ item.instituteAlias }}
17             </a-checkbox>
18           </a-checkbox-group>
19         </a-form-item>
20 
21 
22    // 全選、反選研究院
23     const onCheckAllInstitute = bool => {
24       if (bool) {
25         modelRef.instituteIds = state.list.map(v => v.instituteId)
26       } else {
       // 反選
27 const reverseInstitute = [] 28 state.list.forEach(v => { 29 const index = modelRef.instituteIds.findIndex(x => x === v.instituteId) 30 if (index === -1) { 31 reverseInstitute.push(v.instituteId) 32 } 33 }) 34 modelRef.instituteIds = reverseInstitute 35 } 36 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM