Latihan MVC Part 3

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #191583

    Setelah mengikuti video kenapa masih ada error yah. untuk error yg keluar sebagai berikut:
    TypeError: Cannot read properties of undefined (reading ‘id’)

    `const fs = require(“fs”);

    class TodoModel {
    constructor(id, task, status) {
    this.id = id;
    this.task = task;
    this.status = status;
    }
    // untuk mengambil data dari file json
    static getDataJson() {
    let data = fs.readFileSync(“./data.json”, “utf8”);
    let parseData = JSON.parse(data);
    let todoData = parseData.map((el) => {
    /** map untuk membuat array baru*/
    const { id, task, status } = el;
    return new TodoModel(id, task, status);
    });
    // console.log(TodoController); ubah menjadi return
    return todoData;
    }
    static read() {
    let todoData = this.getDataJson();
    return todoData;
    }
    static add(todo) {
    let todoData = this.getDataJson;
    let id = todoData[todoData.length – 1].id + 1; >>>>>>>>>> DISINI LETAK ERRORNYA <<<<<<<<<<<<
    // let temp = new TodoModel(id, task, status);
    // todoData.push();
    // console.log(paramsTodo[0]); /** untuk task */
    console.log(id);
    }
    }

    module.exports = TodoModel;

    #193324

    Gambar
    izin menjawab yaa.
    ketika memanggil fungsi, hukumnya wajib untuk menambahkan buka dan tutup kurung.
    kalau yang saya lihat, ketika kamu hendak memanggil fungsi static getDataJson(), maka harus disematkan tanda () nya.

    #194849
    Coach Vincent
    Moderator

      Baik terima kasih kak untuk jawabannya

    Viewing 3 posts - 1 through 3 (of 3 total)
    • You must be logged in to reply to this topic.
    Shopping cart0
    There are no products in the cart!
    Continue shopping