Difference between revisions of "QuestionGroupLeaf class"
(One intermediate revision by the same user not shown) | |||
Line 25: | Line 25: | ||
=== <span style="color:#DF8621">'''Examples'''</span> === | === <span style="color:#DF8621">'''Examples'''</span> === | ||
− | |||
<source lang="javascript"> | <source lang="javascript"> | ||
− | number qnaireRId = | + | //Find a group leaf by its question |
+ | number qnaireRId = 17148177; | ||
QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId); | QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId); | ||
+ | //QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups; | ||
QuestionGroupLeaf leaf = root.FindByQuestion("Q1"); | QuestionGroupLeaf leaf = root.FindByQuestion("Q1"); | ||
− | print(leaf.GroupName);// | + | print(leaf.GroupName);//G1 |
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //create new group leaf | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | QuestionGroupLeaf g1 = new QuestionGroupLeaf ("G1", qt); | ||
+ | g1.SetQuestions({"Q1", "Q2"});//Questions must in order | ||
+ | //add the group leaf to group root | ||
+ | array groupRoot = qt.Groups.GetChildGroups(); | ||
+ | groupRoot.Add(g1); | ||
+ | qt.Groups.SetChildGroups(groupRoot); | ||
+ | qt.Save(true); | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //add more questions for an existing group leaf | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | QuestionGroupLeaf g1 = qt.Groups.FindByName("G1"); | ||
+ | // add more question to questions array | ||
+ | array questions = g1.GetQuestions(); | ||
+ | questions.Add("Q3"); | ||
+ | g1.SetQuestions(questions); | ||
+ | qt.Save(true); | ||
</source> | </source> |
Latest revision as of 10:11, 11 May 2022
QuestionGroupLeaf
Question group leaf.
Parent class
Inherits from QuestionGroupTree
Constructors
- (string name "Group name", QuestionnaireTemplate qt "Questionnaire template") - Create s leaf group
Methods
- Array of String GetQuestions() - Return label of questions in group
- Empty SetQuestions(Array of String labels "Question labels") - Set questions in group by their label
- (From object) string ToString() - The string representation of the object.
Properties
- (From QuestionGroupTree) Array of string AllQuestions { get; } - Labels of all questions in this group
- int Count { get; } - How many children in this group
- (From QuestionGroupTree) string GroupName { get; set; } - Name of question group
- (From QuestionGroupTree) bool IsLeaf { get; } - Check if it is leaf group or not
- string ObjectTypeName { get; } - The name of the type of object.
- (From QuestionGroupTree) number SelectCount { get; set; } - How many child items will be used for Sequence_Command_RandomizedSelect or Sequence_Command_RotateSelect
- (From QuestionGroupTree) SequenceCommand constant SequenceCommand { get; set; } - Which kind of this group is it, use constant Sequence_Command_xxx
- (From QuestionGroupTree) string SequenceType { get; } - Respent SequenceCommand as string
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
Examples
//Find a group leaf by its question
number qnaireRId = 17148177;
QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId);
//QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups;
QuestionGroupLeaf leaf = root.FindByQuestion("Q1");
print(leaf.GroupName);//G1
//create new group leaf
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupLeaf g1 = new QuestionGroupLeaf ("G1", qt);
g1.SetQuestions({"Q1", "Q2"});//Questions must in order
//add the group leaf to group root
array groupRoot = qt.Groups.GetChildGroups();
groupRoot.Add(g1);
qt.Groups.SetChildGroups(groupRoot);
qt.Save(true);
//add more questions for an existing group leaf
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupLeaf g1 = qt.Groups.FindByName("G1");
// add more question to questions array
array questions = g1.GetQuestions();
questions.Add("Q3");
g1.SetQuestions(questions);
qt.Save(true);