Skip to content

Commit

Permalink
custom-cards#86 Allow dotted object notation for the data option
Browse files Browse the repository at this point in the history
This only works for attributes.
  • Loading branch information
Veejer authored Sep 18, 2022
1 parent 74baad7 commit 4aed6ac
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions flex-table-card.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

// VERSION info
var VERSION = "0.7.1";
var VERSION = "0.7.3";

// typical [[1,2,3], [6,7,8]] to [[1, 6], [2, 7], [3, 8]] converter
var transpose = m => m[0].map((x, i) => m.map(x => x[i]));
Expand Down Expand Up @@ -281,7 +281,28 @@ class DataRow {
} else {
// no matching data found, complain:
//raw_content.push("[[ no match ]]");
raw_content.push(null);

let pos = col_key.indexOf('.');
if (pos < 0)
{
raw_content.push(null);
}
else
{
// if the col_key field contains a dotted object (eg: day.monday)
// then traverse each object to ensure that it exists
// until the final object value is found.
// if at any point in the traversal, the object is not found
// then null will be used as the value.
let objs = col_key.split('.');
let value = this.entity.attributes;
if (value) {
for (let idx = 0; value && idx < objs.length; idx++) {
value = (objs[idx] in value) ? value[objs[idx]] : null;
}
}
raw_content.push(value);
}
}

// @todo: not really nice to clean `raw_content` up here, why
Expand Down

0 comments on commit 4aed6ac

Please sign in to comment.