Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Javascript Asynchronous insertion into newly generated element

code

<template>
  <!-- record has been declared -->
  <a-button @click="edit(record)">edit</a-button>
  <a-modal data-source="treeSelectData">
    <a-form-item label="content">
      <div id="content"></div>
    </a-form-item>
  </a-modal>
</template>
import Editor from "wangeditor"; // a Rich Text Format Editor

// variables has been declared
const edit = (record: any) => {
  modalVisible.value = true; // show the a-modal
  doc.value = Tool.copy(record);

  treeSelectData.value = Tool.copy(docs.value);
  setDisable(treeSelectData.value, record.id);
  treeSelectData.value.unshift({ id: "0", name: "root" }); // treeSelectData is the datasource of a-modal

  const editor = new Editor("#content");
  editor.create();
};

description

The error is Invalid selector: #content and show no editor on webpage(the modal has been shown). The modal will only appear when I press the edit button. That is to say, there was no element <div id="content"></div> in DOM before.

But if function edit is transformed into an asynchronous function, and adding await before treeSelectData.value.unshift({ id: "0", name: "root" });, no error will be reported and it will be displayed normally out editor.

// ...
const edit = async (record: any) => {
  // ...
  await treeSelectData.value.unshift({ id: "0", name: "root" }); // treeSelectData is the datasource of a-modal

  const editor = new Editor("#content");
  editor.create();
};

Why?

My guess is that the a-modal will only show when the data source is ready. idk.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!