我正在编写一个关于SurveyJS的调查,我有一个关于问题中的格式可能性的问题。
在this问题中,我想要48。和49。作为同一问题的一部分,但我无法以这样的方式格式化多项选择题样式的问题,其中文本间隔。在SurveyJS中有什么方法可以做到这一点吗?
发布于 2021-11-30 11:59:54
您可以使用the markdown功能。
下面是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?",
...
}和markdown初始化:
//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: "
}, {
"value": "cat",
"text": "Cat: "
}, {
"value": "parrot",
"text": "Parrot "
}
]
}
]
};
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>
https://stackoverflow.com/questions/70145055
复制相似问题