未捕获(承诺中)TypeError:无法读取未定义的属性“属性”

时间:2020-06-28 13:45:28

标签: javascript ruby-on-rails ruby

我有一个非常基本的单页应用程序,当我单击以创建新实例时,控制台中显示Sample Data ============= Users ------------------ user_id, user_name ------------------ 1, User_A 2, User_B 3, User_C Books ------------------ book_id, book_name ------------------ 1, Book_A 2, Book_B 3, Book_C Users_Books ----------------------------------- assigned_date, user_id, book_id ----------------------------------- 01-01-2020, 1, 1 02-01-2020, 1, 2 03-01-2020, 1, 3 04-01-2020, 2, 1 05-01-2020, 3, 1 06-01-2020, 4, 1 Sample Output ============================== user_id, user_name, json_col ------------------------------ 1, User_A, (See Json Output below for this row) 2, User_B 3, User_C [{ "assigned_date": "01-01-2020", "user_id": "1", "book_id": "1", "book_detail": { "book_id": "1", "book_name": "Book_A" } }, { "assigned_date": "02-01-2020", "user_id": "1", "book_id": "2", "book_detail": { "book_id": "2", "book_name": "Book_B" } }, { "assigned_date": "03-01-2020", "user_id": "1", "book_id": "3", "book_detail": { "book_id": "3", "book_name": "Book_C" } }] 。当我刷新页面时,将显示新实例。

Uncaught (in promise) TypeError: Cannot read property 'attributes' of undefined

我有一个使用带有属性的序列化器的Ruby On Rails后端

function postFetch(name, description, image_url, event_id) {
  const bodyData = {name, description, image_url, event_id}
  fetch(endPoint, {
    method: "POST",
    headers: {"Content-Type": "application/json"},
    body: JSON.stringify(bodyData)
  })
  .then(response => response.json())
  .then(hike => {
    console.log(hike);
    const hikeData = hike.data
    let newHike = new Hike(hikeData, hikeData.attributes)
    document.querySelector('#hike-container').innerHTML += newHike.renderHikeCard()
  })

这是我第一次发布。抱歉,如果这样做没有意义。我是编码的新手,却卡在此错误上。任何帮助将不胜感激。

0 个答案:

没有答案