How to access nested data when key/property names have a space?
How to access nested data when key/property names have a space?
Dear all,
I am a scientist; not so much a programmer and am exploring the use of DataTables as a front end to a CouchDB database to keep track of things in my lab. Loading the data via AJAX has been a cinch, but now I am having a difficult time accessing nested data. To be clear, an excerpt of the returned JSON looks something like this:
{
"total_rows": 85,
"offset": 0,
"rows": [
{
"id": "1496f4744279d8016cc699d8ba049c09",
"key": "1496f4744279d8016cc699d8ba049c09",
"value": 1,
"doc": {
"Sequence Name": "e2_fwd",
"Sequence": "TGA CTT GTG CTC CCC ACT TT",
"Tm (50mM NaCl) C": 56.7673331659
}
},
...
Using "dataSrc": "rows" I am easily able to access the data, but my problem results from the fact that many of the important property names/keys have spaces in them. I am unable to access them using ECMAScript Bracket Notation:
"columns": [
{"data": "key"},
{"data": "doc['Sequence Name']"},
{"data": "doc.Sequence"}
]
The middle column in my table, which should have the sequence name, is blank, whereas the first and last columns (non-nested, and nested data, respectively) both work fine.
Any help or insight is appreciated very much.
Kind regards
This question has an accepted answers - jump to answer
Answers
You should be able to just do:
{ data: 'doc.Sequence Name' }
. Example.The
columns.data
option isn't a strict ES parser - it just uses the basic style of object notation.Allan