reactjs 除某个值外,调查选择随机顺序

wfveoks0  于 2023-01-04  发布在  React
关注(0)|答案(1)|浏览(98)

我在surveyjs中的选择顺序有问题,我想随机选择除1值以外的顺序(例如: Camel )总是在底部。

var json = {
"elements": [{
"type": "imagepicker",
"name": "Picture",
"title": "What animal would you like to see first ?",
"choices": [
 {
  "value": "lion",
  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
}, {
  "value": "giraffe",
  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg"
}, {
  "value": "panda",
  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg"
}, {
  "value": "camel",
  "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg"
 }]
}]};

window.survey = new Survey.Model(json);
var q = survey.getQuestionByName('Picture');
q.choicesOrder = "random";
q.showLabel = "true";
kupeojn6

kupeojn61#

我用你的代码和最新的SurveyJS创建了一个例子。它看起来不错。
请尝试更新SurveyJS版本到最新。谢谢。

Survey
    .StylesManager
    .applyTheme("default");

var json = {
  "elements": [{
  "type": "imagepicker",
  "name": "Picture",
  "title": "What animal would you like to see first ?",
  "choices": [
   {
    "value": "lion",
    "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
  }, {
    "value": "giraffe",
    "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg"
  }, {
    "value": "panda",
    "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg"
  }, {
    "value": "camel",
    "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg"
   }]
}]};

window.survey = new Survey.Model(json);
var q = survey.getQuestionByName('Picture');
q.choicesOrder = "random";
q.showLabel = "true";

$("#surveyElement").Survey({model: survey});
<!DOCTYPE html>
<html>
    <head>
        <title>One choice - Radio Group question, jQuery Survey Library Example</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="https://unpkg.com/jquery"></script>
        <script src="https://surveyjs.azureedge.net/1.0.53/survey.jquery.js"></script>
        <link href="https://surveyjs.azureedge.net/1.0.53/survey.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="./index.css">

    </head>
    <body>
        <div id="surveyElement"></div>
        <div id="surveyResult"></div>

        <script type="text/javascript" src="./index.js"></script>

    </body>
</html>

相关问题