更改类型矩阵Survey.js中的行文本

时间:2019-03-18 09:53:56

标签: javascript jquery surveyjs

我正在使用surveyjs建立最佳的员工调查项目。在矩阵类型中工作时,我很难用实名员工更改文本“ employee1,employee2,employee3” see picture。 到目前为止,这是我的代码:

var json = {
    title: "Software developer survey.",
    pages: [
   {
       title: "Part 1",

       questions: [
           {
               type: "matrix",
               name: "Question1",
               //isAllRowRequired: true,
               title: "Please indicate if you agree or disagree with the following statements",
               columns: [
                   {
                       value: 1,
                       text: "Strongly Disagree"
                   }, {
                       value: 2,
                       text: "Disagree"
                   }, {
                       value: 3,
                       text: "Neutral"
                   }, {
                       value: 4,
                       text: "Agree"
                   }, {
                       value: 5,
                       text: "Strongly Agree"
                   }
               ],
               rows: [
                   {
                       value: "valueEmployee1",
                       text: "Employee1 ![Employee1](https://bezone.files.wordpress.com/2008/02/soeharto.jpg =50x50)"
                   }, {
                       value: "valueEmployee2",
                       text: "Employee2"
                   }, {
                       value: "valueEmployee3",
                       text: "Employee3"
                   }
               ]
           },
           //
       ]
   },

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您可以动态添加矩阵行:

var json = {
    questions: [
        {
            type: "matrix",
            name: "score",
            title: "Please score the employees in the list",
            columns: [
                {
                    value: 1,
                    text: "Bad"
                }, {
                    value: 2,
                    text: "So-so"
                }, {
                    value: 3,
                    text: "Good enough"
                }, {
                    value: 4,
                    text: "Good"
                }, {
                    value: 5,
                    text: "Excellent"
                }
            ],
            rows: [
            ]
        }
    ]
};

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

var q = survey.getQuestionByName("score");

var employees = [{ id: "id1", name: "John"}, { id: "id2", name: "Ben"}, { id: "id3", name: "Chack"}]

employees.forEach(function(employee) {
  q.rows.push(new Survey.ItemValue(employee.id, employee.name));
});

这是工作示例-https://plnkr.co/edit/OMBt1n02Qc8f5znUmOHE?p=preview