日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Cannot read property ‘forEach‘ of undefined

作者:小陳同學,, 更新時間: 2022-04-12 編程語言

Cannot?read?property?'forEach'?of?undefined

?

forEach ,用來遍歷對象,如果為undefined,沒有屬性,就會錯誤。

解決思路:在遍歷對象之前判斷對象是否為空,然后再去遍歷該對象。

?

??//?選擇角色

??sel_role(item)?{

????this.sel_role_id?=?item.r_id;

????this.sel_role_name?=?item.r_name;

????//遍歷之前檢查是否存在,否則會報錯:Cannot?read?property?'forEach'?of?undefined

????if?(!this.authority_list)?{

??????return

????}

????this.authority_list.forEach(element?=>?{

??????element['disabled']?=?false;

??????if?(element.children)?{

????????element.children.forEach(child?=>?{

??????????child['disabled']?=?false;

????????});

??????}

????});

?

原文鏈接:https://blog.csdn.net/ping_lvy/article/details/116856039

欄目分類
最近更新