簡體   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