首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SurveyJS上的改革性问题?

SurveyJS上的改革性问题?
EN

Stack Overflow用户
提问于 2021-11-28 15:51:32
回答 1查看 29关注 0票数 0

我正在编写一个关于SurveyJS的调查,我有一个关于问题中的格式可能性的问题。

this问题中,我想要48。和49。作为同一问题的一部分,但我无法以这样的方式格式化多项选择题样式的问题,其中文本间隔。在SurveyJS中有什么方法可以做到这一点吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-30 11:59:54

您可以使用the markdown功能。

下面是json:

代码语言:javascript
复制
{
...
"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?",
...
}

和markdown初始化:

代码语言:javascript
复制
//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;
    });

如果你愿意,你也可以选择另一个降价转换器。以下是工作示例:

代码语言:javascript
复制
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");
代码语言:javascript
复制
<!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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70145055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档