A
A
AaronOrtega2021-03-20 01:02:40
JavaScript
AaronOrtega, 2021-03-20 01:02:40

How to deal with wordpress 'query' attribute?

Good evening, the next question. I created a widget and I need to somehow store an array of data in its props.
https://developer.wordpress.org/block-editor/refer...
I need to save an array of data, and as I understand it, this is an ideal option.
What I did:
Created an attribute

span: {
            type: 'array',
            source: 'query',
            selector: 'span',
            query: {
                value: {
                    type: 'string',
                    source: 'attribute',
                    attribute: 'value',
                }
            }
        }

further created the span itself in edit:
el(
            'span',
            {
                value: 'test',
                onClick: test
            },
            'span text'
        ),

And of course the test function, which is called when clicked
function test(event){
            span =  [
                { "value": "https://lorempixel.com/1200/800/",},
                { "value": "https://lorempixel.com/50/50/",}
              ];
            props.setAttributes({span: span});
        }

After reloading the page - props.attributes.span = 0
But when saving, everything goes to the main page, only the edit can't be configured in any way.
What am I doing wrong? I suspect that I misunderstood query, but I killed enough assholes and did not find a solution. :nine

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AaronOrtega, 2021-03-20
@AaronOrtega

I figured
out Edith is taken based on save
lol
while I am writing a question - I myself find the answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question