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

173
Views
¿Cómo cambiar la propiedad del elemento de nodo SlateJS onChange?

¿Cómo cambiar la propiedad del elemento Node en el método SlateJS OnChange?

Tengo un elemento inicial como antes, ¿observa la propiedad 'id'? En OnChange, quiero establecer dinámicamente la propiedad id. Vea a continuación la implementación, más o menos solo la configuración básica de reacción de SlateJs

 const initialValue: Descendant[] = [ { type: 'paragraph', id: '', children: [ { text: 'This is editable plain text, just like a <textarea>!', }, ], }, ]

Componente Slate React

 <Slate editor={editor} value={textContent} onChange={currTextContent => { // Logic for newlines if (currTextContent.length > textContent.length) { // Same example from slatejs on how to save content const isAstChange = editor.operations.some( op => 'set_selection' !== op.type, ) if (isAstChange) { // Set id property of new line currTextContent[0].id = 'test' } } settextContent(currTextContent) }}> <Editable placeholder="Enter some rich text…" spellCheck autoFocus /> </Slate>

Sin embargo, dice que la propiedad .id es de solo lectura. La misma historia sucede si tuviera que intentar configurar todo el objeto. Es de solo lectura. Agregar nuevas propiedades a través de currTextContent[0].newID también da un error, el objeto no es extensible

 currTextContent[0] = { type: 'paragraph', id: '', children: [ { text: 'This is editable plain text, just like a <textarea>!', }, ], }

¿Cómo puedo cambiar (o agregar) la propiedad del elemento del nodo SlateJS en el método onChange? ¿Hay alguna función para hacer esto en la clase Editor?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Por lo tanto, en realidad no puede cambiar los nodos en onChange ya que son de solo lectura. En su lugar, deberá usar la transformación API Slate para insertar o agregar nuevas propiedades como se muestra a continuación.

 Transforms.setNodes( editor, { id: '123', }, { at: [0] }, )

Eso insertaría la propiedad, id = 123, en el nodo[0].

about 4 years ago · Juan Pablo Isaza Report
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!