0

我正在对 SurveyJS 进行调查,我对问题中的格式化可能性有疑问。

这个问题中,我希望 48. 和 49. 成为同一个问题的一部分,但我无法以文本间隔开的方式格式化多项选择样式的问题。有什么方法可以在 SurveyJS 中做到这一点?

4

1 回答 1

0

您可以使用降价功能。

这是json:

{
...
"title": "Some long text Some long text  Some long text Some long text Some long text  </br></br></br></br> other text other textother textother text other text?",
...
}

和降价初始化:

//Create showdown markdown converter
var converter = new showdown.Converter();
survey
    .onTextMarkdown
    .add(function (survey, options) {
        //convert the markdown text to html
        var str = converter.makeHtml(options.text);
        //remove root paragraphs <p></p>
        str = str.substring(3);
        str = str.substring(0, str.length - 4);
        //set html
        options.html = str;
    });

如果您愿意,您也可以使用另一个降价转换器。这是工作示例:

Survey
    .StylesManager
    .applyTheme("modern");

var json = {
    questions: [
        {
            "type": "radiogroup",
            "hasOther": true,
            "isRequired": true,
            "name": "favoritePet",
            "title": "Some long text Some long text  Some long text Some long text Some long text  </br></br></br></br> other text other textother textother text other text?",
            "choices": [
                {
                    "value": "dog",
                    "text": "Dog: ![A dog](https://surveyjs.io/Content/Images/examples/markdown/dog.svg =14x14)"
                }, {
                    "value": "cat",
                    "text": "Cat: ![A cat](https://surveyjs.io/Content/Images/examples/markdown/cat.svg =14x14)"
                }, {
                    "value": "parrot",
                    "text": "Parrot ![A parrot](https://surveyjs.io/Content/Images/examples/markdown/parrot.svg =14x14)"
                }
            ]
        }
    ]
};

window.survey = new Survey.Model(json);

survey
    .onComplete
    .add(function (sender) {
        document
            .querySelector('#surveyResult')
            .textContent = "Result JSON:\n" + JSON.stringify(sender.data, null, 3);
    });

//Create showdown markdown converter
var converter = new showdown.Converter();
survey
    .onTextMarkdown
    .add(function (survey, options) {
        //convert the markdown text to html
        var str = converter.makeHtml(options.text);
        //remove root paragraphs <p></p>
        str = str.substring(3);
        str = str.substring(0, str.length - 4);
        //set html
        options.html = str;
    });

survey.render("surveyElement");
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Use markdown to render images in title and question elements, Knockoutjs Survey Library Example</title><meta name="viewport" content="width=device-width"/>
        <script src="https://unpkg.com/knockout@3.5.1/build/output/knockout-latest.js"></script>
        <script src="https://unpkg.com/survey-knockout@1.8.79/survey.ko.min.js"></script>
        <link href="https://unpkg.com/survey-core@1.8.79/modern.min.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="./index.css">
        <script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.6.4/showdown.min.js"></script>
    </head>
    <body>
        <div id="surveyElement" style="display:inline-block;width:100%;"></div>
        <div id="surveyResult"></div>
        <script type="text/javascript" src="./index.js"></script>
    </body>
</html>

于 2021-11-30T11:59:53.700 回答