Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda