有时候我们需要判断数组中是否包含某个状态/元素,最暴力的方式就是对数组进行遍历,但是还有更优雅的方式去实现。
youMethods() {
if (this.choosedSellectionList.length > 0) {
let availableStateFlag = this.choosedSellectionList.findIndex(item => item.availableState == 0);
if (availableStateFlag != -1) {
this.$modal.msgError("包含不可用状态的数据信息!");
return
}
let matchOrNotFlag = this.choosedSellectionList.findIndex(item => item.matchOrNot == '1');
if (matchOrNotFlag != -1) {
this.$modal.msgError("包含已匹配的数据信息!");
return
}
this.autoMatch()
}
},