How to use variables inside of then() in dataviewjs

hi, i am trying to make my own user interface with dataviewjs. That’s my code :

const container = dv.container;
container.setAttribute('class', 'document--full-page');

const Title = dv.el('h1', 'Physique');
Title.style.fontSize = '70px';

const SubTitle = dv.el('h2', 'Cours :');
SubTitle.style.fontSize = '16px';
SubTitle.style.fontWeight = 'normal';

const Separator = dv.el('hr', '');

const load = dv.io.load("json.md")

container.appendChild(Title);
container.appendChild(SubTitle);
container.appendChild(Separator);

the output of dv.io.load(“json.md”) is

  1. Promise {}

  2. [[Prototype]]: Promise

  3. [[PromiseState]]: “fulfilled”

  4. [[PromiseResult]]: “My target content”

Things I have tried

i’ve tried to use then() method
this is what i’ve done :
const load = dv.io.load(“json.md”).then(data => {
console.log(data)
})
and it works ! data is the information i wanted. But i don’t know how to extract this value outside the then method. So my questions are :

  • is there a way to extract variables from then() and use them in the script
  • how to precise i want the value of [[PromiseResult]]

thanks for helping me :slight_smile: :slight_smile:

Isn’t it
const data = await dv.io.load(…)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.