/
index.js
26 lines (22 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { getInstance } from 'd2/lib/d2';
// The example query you were asking for would look somewhat like this. (You said you figured it out already, but figured i might show it anyhow)
// Note that when loading fields, separately it would be dangerous to call `.save()` on the model as we currently have to use REPLACE as a merge strategy for d2.
export function deeperFilteringExample(d2) {
d2.models.dataSet
.list({fields: 'name,id,sections[id,name,dataElements[id,name,valueType]]' })
.then(dataSets => {
console.log('Deeper models example 2:');
dataSets
.toArray()
.forEach(dataSet => {
dataSet.sections
.toArray()
.forEach(logSectionsWithDataElementNames);
});
});
}
function logSectionsWithDataElementNames(section) {
const dataElementNames = section.dataElements.toArray().map(dataElement => dataElement.name);
console.log(section.name);
console.log(dataElementNames);
}