for(let i=0;i<=res.data.length;i++){
res.data[i]['class'] = 'biaoqian-red';
}
console.log(res.data);
报错:cannot set property xxx of undefined

原因

因为res.data[i]['class']可能是undefined,如果再给res.data[i]['class']动态添加属性的话就会报这样的错误

 
解决:
for (let i = 0; i <= res.data.length; i++) {
  if(rea.data[i] != undefined){
    res.data[i]['class'] = 'biaoqian-red';
  }
}

js - cannot set property xxx of undefined的更多相关文章

  1. angular2在模板中使用属性引发Cannot read property 'xxx' of undefined

    angular在模板中使用属性引发Cannot read property 'xxx' of undefined 在使用ng2的过程中,发现模板中如下方式 <li *ngFor="le ...

  2. 73.node.js开发错误——TypeError: Cannot set property 'XXX' of undefined

    转自:https://blog.csdn.net/fd214333890/article/details/53467429

  3. ?.可选链操作符( ?. ) 可选链运算符可防止抛出 TypeError: Cannot read property ’xxx' of undefined。

    可选链操作符( ?. )允许读取位于连接对象链深处的属性的值,而不必明确验证链中的每个引用是否有效.?. 操作符的功能类似于 . 链式操作符,不同之处在于,在引用为空(nullish ) (null ...

  4. Error in nextTick: "TypeError: Cannot set property 'xxx' of undefined"解决办法

    vue项目在控制台中报这个错误时,当看到nextTick词时想到vue的$nextTick()方法 Vue 在更新 DOM 时是异步执行的.只要侦听到数据变化,Vue 将开启一个队列,并缓冲在同一事件 ...

  5. vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined

    我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...

  6. index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined

    使用 webpack 编译 Vue 项目时出现报错: index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined ...

  7. 【jQuery】jquery中 使用$('#parentUid').attr(parentUid);报错jquery-1.11.3.min.js:5 Uncaught TypeError: Cannot read property 'nodeType' of undefined

    jquery中 使用$('#parentUid').attr(parentUid);报错jquery-1.11.3.min.js:5 Uncaught TypeError: Cannot read p ...

  8. JS报错:Cannot read property 'type' of undefined

    在做图片上传功能的时候,遇到了JS无法识别图片type的问题,在使用过程中是没有问题的,但是不知道为什么浏览器的Console报这个错误: Uncaught TypeError: Cannot rea ...

  9. js 报错 Uncaught TypeError: Cannot read property 'trim' of undefined

    jquery Uncaught TypeError: Cannot read property 'trim' of undefined 报错原因及解决方案 $.trim() 函数用于去除字符串两端的空 ...

随机推荐

  1. Date3.19

    1.正则表达式的定义及使用2.Date类的用法3.Calendar类的用法========================================================1正则表达式的 ...

  2. 献上一款漂亮的手写PHP验证码

    献上一款漂亮的PHP验证码,可以根据个人需求作调整,代码如下(审美观不同,欢迎吐槽): <?php /** * Author: xiongwei * Email: 695704253@qq.co ...

  3. ORACLE_ERP帐务分录

      ORACLE MRPII各模块会计分录   第一章 采购模块 一.资产采购(科目来源:库存组织) 1.物料接收 借  材料采购     接收数量*采购单价 贷 应计暂估     接收数量*采购单价 ...

  4. dssfsfsfs

    一直都好使啊..好使 好使 MainActivity://overover package com.example.sockettest; import java.io.BufferedReader; ...

  5. vee-validate表单校验的基本使用

    今天主要记录一下用vee-validate来进行表单校验的几个基本使用.包括最基础的必填和长度校验:异步请求服务的校验(重名校验),还有延迟校验.如何引入等就不在这里赘述了,直接进入主题. 1.必填和 ...

  6. [other] 代码量代码复杂度统计-lizard

    [other] 代码量代码复杂度统计-lizard lizard的可以用来统计下面的一些数据 不包含代码注释的代码行数 CCN 代码的复杂度,也就是分支复杂度 token的个数(关键字,标示符,常量, ...

  7. URLRewrite 实现方法详解

    所谓的伪静态页面,就是指的URL重写,在ASP.NET中实现非常简单首先你要在你的项目里引用两个DLL:ActionlessForm.dll.URLRewriter.dll,真正实现重写的是 URLR ...

  8. 搭建基于MinGW平台的《OpenGL蓝皮书(OpenGL SuperBibe 5th)》示例代码编译环境

    副标题:搭建基于MinGW平台的<OpenGL超级宝典>(OpenGL蓝皮书第5版)GLTools 编译环境.示例代码:Triangle.cpp @ SB5.zip 以下内容以及方法均参考 ...

  9. RadASM的主题更换!

    RadASM的代码编辑器默认背景色位黑色,我很不习惯,决定更换它,按照下面步骤,我把RadASM的代码编辑器默认背景色成功更换成了白色: 1, 2, 3, 4,

  10. session相关

    判断session是否已失效: HttpSession session=request.getSession(false); getSession(boolean)相比于getSession()更安全 ...