question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about loops

See original GitHub issue

Are you requesting a feature, reporting a bug or ask a question?

Question

What is the current behavior?

If I create a for loop to try and create the same set of questions multiple times with a different subject, I end up with unusable JSON files. It’s because, if I write the JSON normal I get [Object, Object, Object] etc. If I write it in a for loop with heresMyCurrentJSON += {adding this question} I get [object Object],[object Object]. It might be my lack of knowledge of JSON that is the problem, I’m not sure. Could use advice on how to make this work.

What is the expected behavior?

The += should create a usable JSON.

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Tested page URL: Not currently available on the internet

Test code

your_code_here

var allRelationshipJSON = '{';
    for (x in relationship) {
        allRelationshipJSON += {
            questions: [
                { type: "radiogroup", name: "thoughts", title: "How often are thoughts of your " + relationship + " on your mind?", colCount: 0, isRequired: true, choices: ["I don't have a " + relationship, "Never", "Rarely", "sometimes|Occasionally/sometimes", "Often", "time|Most of the Time", "Always"]},
                { type: "matrix", name: "Quality", title: "When I interact with my " +  relationship + ", I feel  ... ", visibleIf: "{thoughts} contains 'Always' or {thoughts}='Often' or {thoughts}='time' or {thoughts}='sometimes' or {thoughts}='Rarely'", visible: false,
                    columns: [{ value: 1, text: "Not True At All" },
                        { value: 2, text: "Sometimes Not True" },
                        { value: 3, text: "Neutral" },
                        { value: 4, text: "Sometimes True" },
                        { value: 5, text: "Completely True" }],
                    rows: [{ value: "competence1", text: "I feel confident I can do things well." },
                        { value: "relatedness1", text: "I feel caring towards this person and cared for by this person." },
                        { value: "autonomy1", text: "I feel a sense of choice and freedom in the things I undertake." },
                        { value: "compentence2", text: "I feel capable at what I do." },
                        { value: "autonomy2", text: "I feel my decisions reflect what I really want." },
                        { value: "relatedness2", text: "I feel close to this person." },
                        { value: "competentce3", text: "I feel competent to achieve my goals." },
                        { value: "autonomy3", text: "I feel my choices express who I really am." },
                        { value: "compentence4", text: "I feel I can successfully complete difficult tasks." },
                        { value: "autonomy4", text: "I feel I have been doing what really interests me." },
                        { value: "relatedness3", text: "I experience a warm feeling with this person." },
                        { value: "relatedness4", text: "I feel connected with this person." },
                        { value: "Something", text: "I feel good about myself." }]}
            ]};
        allRelationshipJSON += ',';
    };
    allRelationshipJSON += '}';
    console.log(allRelationshipJSON);
    return allRelationshipJSON;

### Specify your

* browser: Safari, Chrome. and Firefox
* browser version: All the most current for Mac on 9/17/17
* surveyjs platform (angular or react or jquery or knockout or vue): jquery 3.2.1
* surveyjs version: 0.12.26

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewtelnovcommented, Sep 20, 2017

@alzulas We have added panel dynamic question that does exactly what you need: https://www.surveyjs.io/Examples/Library/?id=questiontype-paneldynamic&platform=jQuery Please take a look at it. You do not repeat the code of dynamic panel.

Thank you, Andrew

0reactions
andrewtelnovcommented, Sep 22, 2017

@alzulas Of course you can. It allows to edit the array of objects. You may optionally allow to add and/or remove an object. You may do not have any dropdown at all and you may put any question / panel inside the dynamic panel.

Thank you, Andrew

Read more comments on GitHub >

github_iconTop Results From Across the Web

Questions and Exercises in Loops - Beginwithjava.com
Question 10. Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed....
Read more >
C programming exercises: For Loop - w3resource
C For Loop [59 exercises with solution] · 1. Write a program in C to display the first 10 natural numbers. · 2....
Read more >
Question loops | Article - Onestopenglish
Each set of question loops is accompanied by procedural guidance on exactly how to conduct the activity in class. Want to know how...
Read more >
Practice questions of Java - Loop loop loop - CodesDope
1. Take 10 integers from keyboard using loop and print their average value on the screen. · 2. Print the following patterns using...
Read more >
Loops - InterviewBit
Loops | In computer programming, loops are used to repeat a block of code. For example, let's say we want to show a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found