SurveyJS:具有多个下拉列表的“无法读取null的属性'indexOf'”

时间:2019-03-18 15:49:00

标签: javascript json surveyjs

我有一个由SurveyJS进行的调查,最后有一个结果页面。我使用以下脚本计算结果:

.add(function (result) {
    var totalScore = result.getAllQuestions().reduce(function(total, q) {
        console.log('totalScore :' + totalScore);
        if(Array.isArray(q.choices)) {
            //console.log('Array.isArray' + Array.isArray);
            return q.choices.reduce(function(s, c) {
                console.log('c.value' + c.value);
                if(q.value.indexOf(c.value) !== -1) {
                    s += c.score;
                    console.log(c.value);
                }
                return s;
            }, total);
        }
        return total;
    }, 0);
    console.debug(totalScore);
    var resultsBlock = document.querySelector('#surveyResult');
    resultsBlock.style.display = "block";
    resultsBlock.innerHTML = "Score total : " + totalScore;
});

此脚本将一直起作用,直到我添加带有条件词“ sub-dropdowns”的下拉问题:

{
    questions: [
        {
        type: "dropdown",
        name: "firstSelection",
        title: "First selection",
        //visibleIf: "{boolCodeAPE}='true'",
        //isRequired: true,
        choices: [
            {
                value: "1",
                score: 0
            },
            {
                value: "2",
                score: 0
            },
            {
                value: "3",
                score: 0
            },
        ]
    },

    // My 3 sub-selections
    {
        type: "dropdown",
        name: "selection1",
        title: "selection1",
        visibleIf: "{codeAPESelection} = '1'",
        //isRequired: true,
        choices: [
            {
                value: "a",
                score: 0
            },
            {
                value: "b",
                score: 0
            },
        ]
    },
    {
        type: "dropdown",
        name: "selection2",
        title: "selection2",
        visibleIf: "{codeAPESelection} = '2'",
        //isRequired: true,
        choices: [
            {
                value: "a",
                score: 0
            },
            {
                value: "b",
                score: 0
            },
            {
                value: "c",
                score: 0
            },
        ]
    },
    {
        type: "dropdown",
        name: "selection3",
        title: "selection3",
        visibleIf: "{codeAPESelection} = '3'",
        //isRequired: true,
        choices: [
            {
                value: "a",
                score: 0
            },
            {
                value: "b",
                score: 0
            },

        ]
    },

 ]
}

当我将此问题添加到代码中时,我的控制台上出现以下错误:Uncaught TypeError:无法读取null的属性'indexOf'

我尝试解决此问题,但是我的JavaScript技能有限...

0 个答案:

没有答案