elementUI 다 중 선택 상자 역 선택 구현 코드
사고:처음에 element UI 홈 페이지 의 예 를 들 어 selection-change 를 사 용 했 지만 현재 변 화 된 선택 만 표시 하고 내 가 페이지 를 넘 기 고 검색 한 후에 데 이 터 를 선택 할 수 있 는 문 제 를 만족 시 킬 수 없 었 다.
toggleSelection(rows) {
if (rows) {
rows.forEach(row => {
this.$refs.multipleTable.toggleRowSelection(row);
});
} else {
this.$refs.multipleTable.clearSelection();
}
}
나중에 api 를 조회 한 결과 다른 2 개의 api 를 발 견 했 습 니 다.페이지 에 로 컬 필드 glht 가 존재 하고 목록 에 선택 한 로 컬 필드 yglht 가 존재 합 니 다.페이지 에 표 시 된 데 이 터 를 계산 할 때마다 목록 의 몇 번 째 데이터 입 니 다.대상 을 직접 넣 으 면 제 가 선택 한 데 이 터 를 업로드 하 는 것 을 선택 하지 않 습 니 다.
emmm..................................................................
탄 상자:
<el-dialog class="contract_modal" title=" " :visible.sync="glht_modal" width="80%" :modal="false" @close="cancel">
<el-form :inline="true" :model="searchData" label-width="90px">
<el-form-item label=" :">
<el-input v-model.trim="searchData.mc_" size="small" class="contract_input"></el-input>
</el-form-item>
<span class="list_btns">
<el-button type="primary" size="small" @click="listSearch(page, 1)" class="con_btn"> </el-button>
<el-button size="small" @click="searchData = {}" class="con_btn"> </el-button>
</span>
</el-form>
<div id="list_body" class="list-body" style="padding-left: 0;">
<el-table :data="tableData" stripe border style="width: 100%" max-height="480" ref="multipleTable" @select-all="handleSelectionAll" @select="handleSelectionChange">
<el-table-column type="selection" width="26" align="right"></el-table-column>
<el-table-column type="index" width="50" label=" " align="left" header-align="left"></el-table-column>
<el-table-column prop="mc_" label=" " width="180" show-overflow-tooltip align="left"></el-table-column>
</el-table>
<div class="list-pagination">
<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page.sync="page.page" :page-sizes="[10, 20, 50, 100]":page-size="page.pageCount"
layout="total, sizes, prev, pager, next, jumper, ->"
:total="page.total"></el-pagination>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="save" size="small"> </el-button>
<el-button @click="cancel" size="small"> </el-button>
</div>
</el-dialog>
methods 에서 선택 할 때 와 선택 할 때 하 는 동작:
// val , ; ,
handleSelectionAll (val) {
//
this.records = JSON.parse(localStorage.getItem('glht'))
if(val.length !== 0) {
//
// this.records = Array.from(new Set(val.concat(this.records))) ! push
// ,
this.tableData.forEach((v) => {
if(this.records.find((e,index) => { return v.id_ === e.id_})){}else {
// push
this.records.push(v)
}
})
} else {
// ,
this.tableData.forEach((v) => {
this.records.forEach((e,index) => {
if (e.id_ === v.id_) {
this.records.splice(index, 1)
}
})
})
}
//
localStorage.setItem('glht', JSON.stringify(this.records))
},
//
handleSelectionChange(val, row) {
//
this.records = JSON.parse(localStorage.getItem('glht'))
if (this.records.length === 0) {
//
this.records = [row]
} else {
if (this.records.filter(i => { return i.id_ === row.id_ }).length === 0) {
// ( ),
this.records.push(row)
} else {
// ( ),
this.records.forEach((e,index) => {
if (e.id_ === row.id_) {
this.records.splice(index, 1)
}
})
}
}
//
localStorage.setItem('glht', JSON.stringify(this.records))
},
methods 에서 팝 업 상자 목록 과 선택 한 데 이 터 를 가 져 옵 니 다:
listGet() {
this.$axios.post("interface", {}, { params: searchData }).then(res => {
if (res.data.success) {
this.tableData = res.data.data.rows;
this.page.total = res.data.data.total;
this.records = JSON.parse(localStorage.getItem('yglht'))
this.toggleSelection(JSON.parse(localStorage.getItem('yglht'))); //
} else {
this.$message.error(res.data.message)
}
})
.catch(err => console.log(err));
},
//
toggleSelection(rows) {
let arr =[]
this.tableData.forEach((e, index) => {
rows.forEach((i, ind) => {
if (e.id_ === i.id_) {
arr.push(this.tableData[index])
}
})
})
if (arr) {
this.$nextTick(() => {
arr.forEach(row => {
this.$refs.multipleTable.toggleRowSelection(row);
});
})
} else {
this.$refs.multipleTable.clearSelection();
}
},methods 에서 단일 작업 을 저장 하고 취소 합 니 다.
save () {
this.glht_modal = false
localStorage.setItem('yglht', localStorage.getItem('glht'))
this.yglht()
},
cancel () {
this.glht_modal = false
//
localStorage.setItem('glht', localStorage.getItem('yglht'))
// this.toggleSelection(JSON.parse(localStorage.getItem('yglht')));
this.listGet({}) // ,
this.yglht()
},
yglht() {
this.list = JSON.parse(localStorage.getItem('yglht'))
// this.list 、
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
vue.js의 컴포넌트 컬렉션 "Element"를 사용하여 다중 선택을 구현합니다.멀티플 셀렉트란 간단하게 말하면 복수 선택 가능한 셀렉트 박스입니다. 의외로 고객이 요구하는 UI상 필요한 것이 많아, 지금까지도 몇번이나 요망에 응해 왔습니다. 대체로 jQuery의 멀티플 셀렉트를 사용하고 있었습...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.