include()メソッド:
arr.includes(searchElement)メソッド:
配列に指定された値が含まれているかどうかを判断するために使用されます。含まれている
場合はtrueを返し、含まれていない場合はfalseを返します。
searchElement:必須。検索する要素の値。
let site = ['runoob', 'google', 'taobao'];
site.includes('runoob'); // true
site.includes('baidu'); // false
arr.includes(searchElement、fromIndex)。
fromIndex:オプション。このインデックスでsearchElementの検索を開始します。
負の場合、検索はarray.length+fromIndexのインデックスから昇順で開始されます。デフォルトは0です。
結果の例
[1, 2, 3].includes(2); //true
[1, 2, 3].includes(4); // false
[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); //true
[1, 2, NaN].includes(NaN); //true
注:fromIndexが配列の長さ以上の場合、falseを返します。配列は検索されません
var arr = ['a', 'b', 'c'];
arr.includes('c', 3); //false
arr.includes('c', 100); // false
注意:
如果 fromIndex 为负值,
计算出的索引将作为开始搜索searchElement的位置。
如果计算出的索引小于 0,则整个数组都会被搜索。
// 数组长度是3
// fromIndex 是 -100
// computed index 是 3 + (-100) = -97
arr.includes('a'、-100); // true
arr.includes('b'、-100); // true
arr.includes('c'、-100); //true
プロジェクトインスタンス
要件はこのようなもので、ページで許可されるデフォルト値は1つだけです。また、フロントエンドはデフォルトをクリックしたときに判断を下すことができるため、インターフェイスデータを要求する必要はありません。もちろん、バックエンドが最善を尽くします。
コード:
handleDefault = async (keys, rows, type) => {
const defaultDate = this.tableRef.getRows() // 获取查询到的数据结果[]
console.log(defaultDate)
let moren = defaultDate.map((item) => { // 循环每一项
return item.defaultFlag // 返回指定的 默认的值
})
console.log(moren)
if(moren.includes(true)) { // 如果这个默认中中有了true
ElNotification({
type: 'error',
message: '项目中包含已默认状态,请重新配置!'
});
} else {
const res = await service.getProcurementTypeId(rows[0]);
this.handleRequestResult(res);
}
};