From 30daa63a58e8bfb13b3e2feb121e13ab6745a354 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Thu, 22 Oct 2020 12:13:48 +0300 Subject: [PATCH] Fixed #555 - DataTable crashes with a "Cannot read property 'xxx' of null" for nested objects --- src/components/utils/ObjectUtils.js | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index 425d4cec1..9a6ee1118 100755 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -58,27 +58,32 @@ export default class ObjectUtils { } static resolveFieldData(data, field) { - if (typeof field === 'function') { - return field(data); - } - else { - if (data && field) { - if (field.indexOf('.') === -1) { - return data[field]; - } - else { - let fields = field.split('.'); - let value = data; - for (var i = 0, len = fields.length; i < len; ++i) { - value = value[fields[i]]; - } - return value; - } + if (data && field) { + if (this.isFunction(field)) { + return field(data); + } + else if(field.indexOf('.') === -1) { + return data[field]; } else { - return null; + let fields = field.split('.'); + let value = data; + for(var i = 0, len = fields.length; i < len; ++i) { + if (value == null) { + return null; + } + value = value[fields[i]]; + } + return value; } } + else { + return null; + } + } + + static isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); } static filter(value, fields, filterValue) {