国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

TypeError: Cannot read properties of undefined (reading ‘NAME‘)報錯解決

這篇具有很好參考價值的文章主要介紹了TypeError: Cannot read properties of undefined (reading ‘NAME‘)報錯解決。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、錯誤查找

問題描述:前端一個el-table表格,一個醫(yī)院查詢到的科室從后端返回時總是顯示不出來,response里面是有數(shù)據(jù)的,這個表格別的醫(yī)院都能顯示出科室,就那個醫(yī)院顯示不出。報錯:TypeError: Cannot read properties of undefined (reading 'NAME')

?查找問題所在,發(fā)現(xiàn)el-table里面有一個:formatter="formatter_DepType",具體方法如下:

const formatter_DepType = function (row, column) {
            if (_this.Type_Ary && row.DEP_TYPE) {
                return _this.Type_Ary.filter((data) => data.CODE == row.DEP_TYPE)[0].NAME;
            }
            return "";
        }

其中Type_Ary里面的內(nèi)容是這樣的:

Type_Ary: [{ CODE: '1', NAME: '門診科室' }, { CODE: '2', NAME: '住院科室' }, { CODE: '3', NAME: '其他' }],

它定義子在data里面。

這樣就發(fā)現(xiàn)錯誤了,科室的DEP_TYPE查詢出來之后如果有和Type_Ary里面的數(shù)據(jù)不一致的就會直接報錯。

二、問題解決

只需要在方法上加個判斷就行了:

const formatter_DepType = function (row, column) {
            if (_this.Type_Ary && row.DEP_TYPE) {
				if(typeof(_this.Type_Ary.filter((data) => data.CODE == row.DEP_TYPE)[0]) =="undefined"){
					return "";
				}
                return _this.Type_Ary.filter((data) => data.CODE == row.DEP_TYPE)[0].NAME;
            }
            return "";
        }

其中:

typeof(_this.Type_Ary.filter((data) => data.CODE == row.DEP_TYPE)[0]) =="undefined"

用來判斷它是否為未定義undefined,如果未定義直接返回空,這樣就不會報錯了。

這個錯誤本質(zhì)是由_this.Type_Ary.filter((data) => data.CODE == row.DEP_TYPE)[0].NAME

引起的,如果科室類型和Type_Ary里面的不一樣就直接為未定義了,再來個.NAME,肯定直接報錯了。

大家的報錯可能和我的不一樣,本文僅供大家參考,當(dāng)然最有可能的錯誤還是:對象沒有數(shù)據(jù),它為undefined。文章來源地址http://www.zghlxwxcb.cn/news/detail-790054.html

到了這里,關(guān)于TypeError: Cannot read properties of undefined (reading ‘NAME‘)報錯解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 微信小程序報錯:[渲染層錯誤] TypeError: Cannot read property ‘$$‘ of undefined

    微信小程序報錯:[渲染層錯誤] TypeError: Cannot read property ‘$$‘ of undefined

    渲染層出錯,滑動圖片組件無法顯示,(swiper是輪播圖插件, 因此錯誤應(yīng)該出現(xiàn)在swiper組件的渲染中 )如圖: wxml在使用swiper組件時,未接收到數(shù)據(jù),因此頁面也不會渲染此項數(shù)據(jù)。 到頁面對應(yīng)的js文件下,將對應(yīng)數(shù)據(jù)傳入data中(我要傳入的數(shù)據(jù)是圖片的url),如圖所示:

    2024年02月11日
    瀏覽(32)
  • 關(guān)于在使用Vuex時終端報錯TypeError: Cannot read properties of undefined (reading ‘state‘)的解決方案

    關(guān)于在使用Vuex時終端報錯TypeError: Cannot read properties of undefined (reading ‘state‘)的解決方案

    下面都是代碼的正確語法書寫和使用,先和自己的代碼對一下,沒有語法錯誤在看后面的解決方案。 1.當(dāng)創(chuàng)建一個vue2項目后并安裝最新的vuex包(沒有指定版本) 2.引入vuex并生成一個store對象(src/store/index.js) 3.在main.js中掛載store(src/main.js) 4.到這里為止都是vuex正確的使用但是終端

    2024年02月13日
    瀏覽(40)
  • 報錯forEach,其實是forEach之前的數(shù)據(jù)未獲取到--TypeError: Cannot read properties of undefined (reading ‘forEach‘)

    跑了個js,測試時F12報錯 報錯如下: Uncaught TypeError: Cannot read properties of undefined (reading \\\'forEach\\\') ? ? at 報錯代碼如下 forEach其實類似于for i in xxx中逐個取出數(shù)據(jù),所以報錯那可能性前面的box_geo1.faces未獲取到數(shù)據(jù)而導(dǎo)致,因而加行代碼驗證下,console.log(\\\'faces信息\\\',box_geo1.faces); 于

    2024年02月13日
    瀏覽(17)
  • 微信小程序常見的報錯問題:TypeError: Cannot read property ‘forceUpdate‘ of undefined

    微信小程序常見的報錯問題:TypeError: Cannot read property ‘forceUpdate‘ of undefined

    微信小程序遇到 Cannot read property \\\'forceUpdate\\\' of undefined是很常見的問題 這是由于?沒有為項目配置 AppID。所以解決我們只需要為其配置AppID即可 登錄微信開發(fā)者文檔,在指南的下面選擇申請賬號菜單 開始 | 微信開放文檔? ? (1)如果使用的是微信開發(fā)者工具軟件 在該軟件的右

    2024年02月12日
    瀏覽(30)
  • TypeError: Cannot read properties of undefined (reading ‘replace‘)

    錯誤一:TypeError: Cannot read properties of undefined (reading \\\'replace\\\') 錯誤二:[Vue warn]: inject() can only be used inside setup() or functional conponents. 解釋:當(dāng)我們使用內(nèi)置 use開頭的鉤子函數(shù)時,不能進(jìn)行嵌套去拿實例。如: 解決:必須在 setup函數(shù) 第一層調(diào)用。

    2024年02月11日
    瀏覽(20)
  • TypeError: Cannot read properties of undefined (reading ‘map‘)

    TypeError: Cannot read properties of undefined (reading ‘map‘)

    控制臺報錯 TypeError: Cannot read properties of undefined (reading \\\'map\\\') 我的錯誤原因: 第一次頁面渲染的時候,map的對象是undefined或null, 解決方法: 在前面加個要進(jìn)行判斷,當(dāng)有值時再去遍歷

    2024年02月07日
    瀏覽(27)
  • Vue項目npm run dev 啟動報錯TypeError: Cannot read property ‘upgrade‘ of undefined

    Vue項目npm run dev 啟動報錯TypeError: Cannot read property ‘upgrade‘ of undefined

    vue項目啟動報錯 TypeError: Cannot read property \\\'upgrade\\\' of undefined ?由于我的vue.config.js文件 里面的代理target為空導(dǎo)致的 ?修改: 結(jié)果就可以正常運行了 ? 參考原文: vue項目運行時報Cannot read property ‘upgrade’ of undefined錯誤_cannot read property \\\'upgrade\\\' of undefined_超帥不是很帥的博客-CSD

    2024年02月14日
    瀏覽(21)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘remove‘)

    在Vue 3中,你可能會遇到“Uncaught TypeError: Cannot read properties of undefined (reading \\\'remove\\\')”這樣的錯誤,這通常是因為在組件銷毀時,嘗試訪問已經(jīng)被銷毀的元素或事件監(jiān)聽器。 為了解決這個問題,你可以在組件銷毀之前,確保移除所有的事件監(jiān)聽器和其他可能導(dǎo)致問題的操作。

    2024年01月20日
    瀏覽(42)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘use‘)

    報錯:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’) 原因:Vue-router版本問題,在vue-router3可在router/index.js中安裝router插件,但4不支持 解決: 1、在router/index.js中,導(dǎo)出{createRouter, createWebHistory}兩個函數(shù) 使用createRouter來創(chuàng)建路由對象 使用createWebHistory函數(shù)賦值給histor

    2024年02月13日
    瀏覽(43)
  • TypeError: Cannot read property ‘setRules‘ of undefined“

    TypeError: Cannot read property ‘setRules‘ of undefined“

    1.uniapp 執(zhí)行小程序表單校驗時報錯 使用如果使用v-if,則使用v-show替換v-if ,即可解決問題

    2024年02月06日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包