繁体   English   中英

未捕获的类型错误:无法读取未定义的属性(读取“x”)

[英]Uncaught TypeError: Cannot read properties of undefined (reading 'x')

我正在使用 react 编写应用程序,但出现此错误 - Uncaught TypeError: Cannot read properties of undefined (reading 'x') at calculateIntersectionX。 当限制常数中有合法的 x 部分时,我真的不知道为什么会收到此错误。

const limits = [
  { x: 12.3456777, y: -12.3456777 },
  { x: 12.3456777, y: -12.3456777 },
  { x: 12.3456777, y: -12.3456777 },
];
for (var i = 0; i < limits.length; i++) {
  for (var g = 0; g < limits.length; i++) {
    if (limits[i] != limits[g]) {
      let a1 = limits[i];
      let a2 = limits[g];
      calculateIntersectionX(avgfakex1, avgfakex2, a1, a2);
      calculateIntersectionY(avgfakey1, avgfakey2, a1, a2);
    }
  }
}


function calculateIntersectionX(p1, p2, p3, p4) {

  var c2x = p3.x - p4.x; // (x3 - x4)
  var c3x = p1.x - p2.x; // (x1 - x2)
  var c2y = p3.y - p4.y; // (y3 - y4)
  var c3y = p1.y - p2.y; // (y1 - y2)

我认为你必须改变:

  • 内循环增加'i'而不是'g'。
  • 考虑只使用一个循环。
  • 在“if (limits[i].= limits[g])”中检查 object 是否等于 object 也许你想检查limits[i].x 是否等于limits[g].x。

考虑修复这些,也许它会帮助你弄清楚:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM