2016-09-01 3 views
-1

를 포함하는 배열을 기반으로 세트 선택 값을 할당하기위한 함수를 만드는내가 프리 - 자바 스크립트를 사용하려고 ... 내가 그래서 나와 함께 곰하시기 바랍니다 .... 자바 스크립트를 완전히 새로운 오전 주어진 수

필요 참가자가 설문 조사에서 일찍이 취하는 객관식 질문의 답을 채 웁니다. 내 변수 "Legchoice"는 여기에 파이프되는 값을 사용합니다. 그러나 응답자가 파이프로 연결될 해당 질문에 대해 하나 이상의 답변을 선택할 수 있기 때문에 여러 값이있을 수 있습니다. "LegChoice"가 주어진 숫자와 같은지 여부를 묻는 스크립트가 있습니다. 어떻게 변경합니까? 그 "LegChoice"는 주어진 숫자를 포함합니다. 응답자가 값 1 & 3에 해당하는 답을 선택하면 4,5,6,7,8,9의 선택 값을 설정할 수 있습니다. 또는 2 & 4에 해당하는 답변을 선택하면 어떻게됩니까? 나는 이것이 의미가 있기를 바랍니다.

감사합니다.

var LegChoice = "${q://QID23/SelectedChoicesRecode}"; 
var LegChoice = parseInt(LegChoice); 


    if (LegChoice==1) { 
    this.setChoiceValue(4,true); 
    this.setChoiceValue(5,true); 
    this.setChoiceValue(6,true); 
    this.setChoiceValue(7,true); 
} 

if (LegChoice== 2) { 
    this.setChoiceValue(4,true); 
    this.setChoiceValue(5,true); 
    this.setChoiceValue(6,true); 
    this.setChoiceValue(7,true); 
} 

if (LegChoice==3) { 
    this.setChoiceValue(6,true); 
    this.setChoiceValue(8,true); 
    this.setChoiceValue(9,true); 
} 

if (LegChoice == 4) { 
    this.setChoiceValue(1,true); 
    this.setChoiceValue(3,true); 
} 
+0

프레임을 만드는 더 좋은 방법은 ... 파이프에있는 값이 숫자 배열 인 경우 ... Legchoice에 1, then this.setchoice 값이있는 경우 내 변수를 설정하는 방법 ... .. Legchoice에 1,2,3,4가 포함 된 경우 ... –

+0

Qualtrics에서 여러 개의 답을 쉼표로 구분 된 문자열로 반환한다는 점을 명심해야합니다. 또한 Java와 JavaScript는 매우 다릅니다. Qualtrics는 Java를 사용하지 않습니다. –

답변

1

각기 다른 답변으로 LegChoice를 분할 한 후 반복해야합니다.

var LegChoices = "${q://QID23/SelectedChoicesRecode}"; 
var that = this; 
LegChoices.split(",").each(function(LegChoice,index) { 
    var LegChoice = parseInt(LegChoice.trim()); 
    if (LegChoice==1) { 
     that.setChoiceValueByRecodeValue(4,true); 
     that.setChoiceValueByRecodeValue(5,true); 
     that.setChoiceValueByRecodeValue(6,true); 
     that.setChoiceValueByRecodeValue(7,true); 
    } 

    //etc... 

}); 

참고 : 코드 값을 파이핑하는 경우 코드 값으로 설정해야합니다.