0

I've created a REST export view to get a paragraph field in a JSON format but I cannot get the result properly, so I used Rest Views module but I got the results including something like these characters \u003Ca href=\u0022\/colors\/gray-metallic\u0022 hreflang=\u0022en\u0022\u003EGray Metallic\u003C\/a\u003E

Also, this paragraph field includes a term reference field.

So I want to render the data properly without these characters and as a plain text

0

I have solved by using jQuery.parseHTML() or you can use Javascript DOMParser

Something like this

$.ajax({
    type: 'GET',
    url: drupalSettings.path.baseUrl + 'REST_VIEW_PATH/' + nid,
    success: function (data) {
        {
            var paragraphField = data[0]['FIELD_NAME'];
            $.each(paragraphField, function (index, item) {
                var fieldItem = $.parseHTML(item.FIELD_ID_IN_PARAGRAPH);
                console.log(fieldItem[0]['innerText']);
            });
        }
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.