Search code examples
javascriptkendo-uikendo-datasource

Kendo dataSource.add - Type Error: o is undefined


I'm trying to add an item to my Kendo DataSource but I keep getting the following error whenever I try and add:

TypeError: o is undefined - kendo.all.min.js (line 50, col 23446)

This happens when I try and use the dataSource.add() method.

sectionNotesDataSource: new kendo.data.DataSource({
    transport: {
        read: {
            url: "/baa/baa/GetNotes",
            dataType: "json",
            type: "GET",
            data: {
                Id: $("#Id").val()
            }
        },
        create: {
            url: "/baa/baa/CreateNote",
            dataType: "json",
            type: "POST"
        },
        parameterMap: function (data, operation) {
            if (operation === "update" || operation === "create") {
                data.CreateDate = _dateToString(data.CreateDate);
                data.LastModDate = _dateToString(data.LastModDate);
            }
            return data;
        }
    },
    schema: {
        model: {
            id: "Id",
            fields: {
                Id: { type: "number", editable: false, nullable: true },
                BaaId: { type: "number", editable: false, nullable: false },
                BaaSectionId: { type: "number", editable: false, nullable: false },
                Body: { type: "string", editable: true },
            }
        }
     }
}),
onNewNote: function (e) {
    var baaId = $(e.currentTarget).data("baaId");
    var baaSectionId = $(e.currentTarget).data("baasection");
    var noteList = $(e.target).closest(".baa-section-notes").find(".section-note-list").data("kendoListView");

    $("#NoteSave").on("click", function() {
        var body = editor.value();
        noteList.add({ BaaId: baaId, BaaSectionId: baaSectionId, Body: body  });
}
});

I have been trying to figure out what is causing this error for the past couple of hours but just can't seem to figure it out.

BaaId, BaaSectionId and Body all contain values so I'm completely lost on this bug.


Solution

  • I ended up solving my issue.

    I changed the line

    noteList.add({ BaaId: baaId, BaaSectionId: baaSectionId, Body: body });
    

    to

    noteList.dataSource.add({ BaaId: baaId, BaaSectionId: baaSectionId, Body: body });