I have a datasource for messages and list a snippet of all the messages on one mobile view and view the full message in another mobile view. I use the schema: parse function to make a snippet of the message on the list messages page. This appears to be working well, however I do get an error message, "message is undefined" whenever I update the datasource.
I also have a similar error "
Anyone any ideas why this is and what I can do to fix it?
I also have a similar error "
rawDate.split is not a function", which is also initiated from the schema and again, only occurs when the datasource is updated.Anyone any ideas why this is and what I can do to fix it?
var messageDataSource = new kendo.data.DataSource({ transport: { read: "/messages/data", dataType: "json", update: { url: function() { var url = "/messages/markasread/" + message_id + "/" + message_read; if (message_read == 0){ if(unread_messages != 0){ var new_unread_messages = unread_messages-1; } else { var new_unread_messages = unread_messages; } } else if (message_read == 1){ var new_unread_messages = unread_messages+1; } $("span#unread_messages").html(new_unread_messages); $("span#unread_messages_hp").html(new_unread_messages); return url; }, type: "POST", dataType: "json" }, destroy: { url: function() { var delurl = "/messages/delete/" + message_id; return delurl; }, type: "DELETE", dataType: "json" } }, error: function(e) { alert(e.responseText); }, sort: { field: "created", dir: "desc" }, schema: { model: { id: "id", fields: { message: { type: "string" }, shortMessage:{ type: "string"}, customer_name: { type: "string" }, customer_telephone: { type: "string" }, ip: { type: "string" }, created: { type: "date", parse: parseDate }, formatedCreated: { type: "string"}, shortCreated: { type: "string" }, email: { type: "string" }, isnew: { type: "string" } } }, parse : function(data) { $.each(data, function(i, val){ //reduce text of message if being used for list var message = val.message; if (message.length > 100){ var shortText = jQuery.trim(message).substring(0, 100).split(" ").slice(0, -1).join(" ") + "..."; } else { var shortText = message; } val.shortMessage = shortText; //format the date var created = parseDate(val.created); val.shortCreated = formatDate(created); val.formatedCreated = val.created; }); return data; } } }); function parseDate(rawDate) { var bits = rawDate.split(/[-\s:]/); var year = bits[2]; var month = bits[1]-1; var day = bits[0]; var hour = bits[3]; var minute = bits[4]; var validDate = new Date( year, month, day, hour, minute ); return validDate; }