Issue #2089💬 AnsweredOpened June 20, 2019by abhilashks19850 reactions

How to reload block content based on trait value change

快速解答by artf

The script content part has NOTHING to do with the editor components... read carefully Components & JS

Read full answer below ↓

Question

I have added new block with some trait value and i want to pass that trait value with ajax call.

代码片段TEXT
Also should be able to reload block when trait value changes. Is that possible? I am pasting my block code.

editor.BlockManager.add('loginBlock', {
        label: 'Login Block',

        attributes: {
            class:'fa fa-sign-in',
            title: 'My title',
            my_field: 'My title'
        },

        content: {
            traits: [{
                type: 'text',
                label: 'Test',
                name: 'model-prop-name',
                changeProp: 1
            }],
            myModelPropName: 'login',
            script: "" +
            "myVar3 = this;" +
            "var xhttp = new XMLHttpRequest();" +
            "xhttp.onreadystatechange = function() {" +
            "if (this.readyState == 4 && this.status == 200) {" +
            "myVar3.innerHTML = this.responseText;" +
            "}" +
            "};" +
            "xhttp.open('GET', '/?index=apiv2', true);" +
            "xhttp.send();"
        }
    });

Answers (2)

artfJuly 3, 2019

The script content part has NOTHING to do with the editor components... read carefully Components & JS

ghostJanuary 10, 2020

try use components methods, for example: editor.getSelected().components(your content)

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.