1、.html文件中对应的radio标签添加点击事件
<label nz-radio (click)="clearRadioValue(item)"></label>
2、实现clearRadioValue方法
(1)定义一个变量,用来存储radio上一次的数据。
lastCards: any;
(2)实现清楚方法,即在点击的时候,用最新的数据与上一次数据进行比较,如果数据相同,说明点击的同一个选项,清楚数据即可。
clearRadioValue = (item) => {
if(this.lastCards && 0 < this.lastCards.length) {
const checkIndex = this.lastCards.findIndex(
i => i.lookupCode === item.lookupCode);
if(this.lastCards[checkIndex].items && 0 < this.lastCards[checkIndex].items.length) {
const lastModelName = this.lastCards[checkIndex].items[0].modelName;
const nowModelName = item.modelName;
if(lastModelName == nowModelName) {
console.log('选择了同一个选项,清除...');
item.modelName = null;
}
}
}
this.lastCards = []
this.lastCards = JSON.parse(JSON.stringify(this.cards));
};