riktar / jkanban

Vanilla Javascript plugin for manage kanban boards
https://www.riccardotartaglia.it/jkanban/
Apache License 2.0
1.06k stars 296 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'dragTo') #174

Closed Brecht272727 closed 1 year ago

Brecht272727 commented 1 year ago

I am trying to make an ajax call with all boards and items inside. The data coming from the ajax is json and look like this:

[
    {
        "id": 1,
        "title": "New",
        "item": [
            {
                "id": 1,
                "title": "ID1
Second line<\/strong><\/div>
Thirth line
View<\/div><\/div>"
            },
            {
                "id": 2,
                "title": "ID2"
            },
            {
                "id": 3,
                "title": "ID3"
            }
        ]
    },
    {
        "id": 2,
        "title": "Working",
        "item": [
            {
                "id": 4,
                "title": "ID4"
            },
            {
                "id": 5,
                "title": "ID5"
            }
        ]
    },
    {
        "id": 3,
        "title": "Done",
        "item": [
            {
                "id": 6,
                "title": "ID6"
            }
        ]
    }
]

And the JS for init the kanban:

var kanban1 = new jKanban({
        element:'#demo1',  
        dropEl: function(el, target, source, sibling) {

          var _target = $(target.parentElement);
          var sorted = [];
          var nodes = kanban1.getBoardElements(_target.data("id"));
          var currentOrder = 0;
          nodes.forEach(function(value, index, array) {
            sorted.push({
              "id": $(value).data("eid"),
              "order": currentOrder++
            })
          });

          console.log(JSON.stringify(sorted));

          var sourceId = $(source).closest("div.kanban-board").attr("data-id"),
              targetId = $(target).closest("div.kanban-board").attr("data-id");

          console.log(sourceId)
          console.log(targetId)

          if(source === target) {
              // same column
          } else {
              // different column
          }

        },        
        boards  : boards
    });

But i got the error Uncaught TypeError: Cannot read properties of undefined (reading 'dragTo') in console?

Brecht272727 commented 1 year ago

I found out myself. It is because of the "id": 1. It has to be "id": "1" (See the double quotes around the numbers)