vue el-table實現(xiàn)多選框回填的示例代碼
更新時間:2024年01月15日 11:30:33 作者:guochanof
摘要:Vue多選框回填是實現(xiàn)表單數(shù)據(jù)高效處理的常見需求,本文主要介紹了vue el-table實現(xiàn)多選框回填的示例代碼,具有一定的參考價值,感興趣的可以了解一下
主要代碼:
//選中列,所有列,表名
toggleSelection(selectRows, totalRows, tablename) {
this.$refs.table.clearSelection();
if (selectRows.length > 0) {
this.$nextTick(() => {
selectRows.forEach(item => {
totalRows.forEach(item1 => {
if (item.userId == item1.userId) {
this.$refs.table.toggleRowSelection(item1);
}
});
});
});
}
},效果:


html
<!-- 添加或修改對話框 -->
<el-dialog :title="title" :visible.sync="open" width="880px" append-to-body :close-on-click-modal="false">
<el-form ref="form" :model="form" :rules="rules" label-width="120px" class="add">
<el-form-item label="分組名稱" prop="nums">
<el-input v-model="form.nums" placeholder="請輸分組名稱" />
</el-form-item>
<el-form-item label="人員" prop="names">
<el-input v-model="form.names" type="textarea" style="width:500px" />
<el-input v-model="form.userIds" type="textarea" style="width:500px" />
<el-button type="primary" plain size="mini" @click="selectProject" style="margin-left:20px">人員選擇</el-button>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">確 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
<!-- 項目選擇 -->
<el-dialog title="選擇人員" :visible.sync="projectOpen" width="1000px" :append-to-body="true" @close="cancelSelsectProject" :close-on-click-modal="false">
<el-form :model="projectQueryParams" ref="projectQueryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="部門" prop="deptId">
<el-select v-model="projectQueryParams.deptId" filterable clearable placeholder="請選擇部門">
<el-option v-for="item in deptOptions" :key="item.id" :label="item.label" :value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="姓名" prop="nickName">
<el-input v-model="projectQueryParams.nickName" placeholder="姓名" clearable />
</el-form-item>
<el-form-item label="編制" prop="name">
<el-select v-model="projectQueryParams.value" placeholder="請選擇">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="projectHandleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="projectResetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="projectList" ref="table" @row-click="projectSelectRow" @selection-change="handleSelectionChange" :row-key="row=>row.userId" :highlight-current-row="true" @cell-dblclick="dblclickRow(row)" border>
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="部門" align="center" prop="dept.deptName" />
<el-table-column label="姓名" align="center" prop="nickName" />
<el-table-column label="編制" align="center" prop="types" />
</el-table>
<pagination v-show="projectTotal > 0" :total="projectTotal" :page.sync="projectQueryParams.pageNum" :limit.sync="projectQueryParams.pageSize" @pagination="getProjectList" />
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitSelectProject">確 定</el-button>
<el-button @click="cancelSelsectProject">取 消</el-button>
</div>
</el-dialog>js
// 多選框選中數(shù)據(jù)
handleSelectionChange(selection) {
this.projectRow = selection;
this.ids = selection.map(item => item.userId);
this.names = selection.map(item => item.nickName);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
//打開項目選擇彈窗
selectProject() {
this.projectOpen = true;
this.getProjectList();
},
/** 查詢項目列表 */
getProjectList() {
this.loading = true;
let rows = this.projectRow;
listUser(this.projectQueryParams).then(response => {
this.projectList = response.rows;
this.projectTotal = response.total;
let selectRows = this.projectRow;
let totalRows = response.rows;
this.loading = false;
this.toggleSelection(selectRows, totalRows);
});
},
//選中列,所有列,表名
toggleSelection(selectRows, totalRows, tablename) {
this.$refs.table.clearSelection();
if (selectRows.length > 0) {
this.$nextTick(() => {
selectRows.forEach(item => {
totalRows.forEach(item1 => {
if (item.userId == item1.userId) {
this.$refs.table.toggleRowSelection(item1);
}
});
});
});
}
},到此這篇關(guān)于vue el-table實現(xiàn)多選框回填的示例代碼的文章就介紹到這了,更多相關(guān)vue el-table多選框回填內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue3界面使用router及使用watch監(jiān)聽router的改變
vue2中使用router非常簡單,但是vue3中略微有些改變,通過本文講解下他的改變,對vue3?watch監(jiān)聽router相關(guān)知識感興趣的朋友一起看看吧2022-11-11
vue+element項目中過濾輸入框特殊字符小結(jié)
這篇文章主要介紹了vue+element項目中過濾輸入框特殊字符小結(jié),本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08
vue實現(xiàn)定義一個全局實例Vue.prototype
這篇文章主要介紹了vue實現(xiàn)定義一個全局實例Vue.prototype,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
vue+element 實現(xiàn)商城主題開發(fā)的示例代碼
這篇文章主要介紹了vue+element 實現(xiàn)商城主題開發(fā)的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
詳解本地Vue項目請求本地Node.js服務(wù)器的配置方法
本文只針對自己需要本地模擬接口于是搭建一個本地node服務(wù)器供自己測試使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
vue實現(xiàn)微信公眾號h5跳轉(zhuǎn)小程序的示例代碼
本文主要介紹了vue實現(xiàn)微信公眾號h5跳轉(zhuǎn)小程序的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08

