samedi 28 juillet 2018

How to populate list of checkbox values with AngularJS?

I am trying to build a quiz application in angular js with serverside for that i have 2 type of choices:

  1. Multiple options for one question (input-checkbox). "dataType": 3,
  2. Single option for one question. (input-radio) "dataType": 2,

I am trying to populate stored answer for multiple checkbox questions in this case storedAnswer is an array, whereas storedAnswer is an integer value for input radio

Note: storedAnswer array contains the option.questionChoiceValue's

My question is how can i populate array value as checked for multiple choice (checkbox) question:

This is my HTML code:

<div ng-repeat="question in data.questionData">

    <span name="multiSelectCheckBox" ng-if="question.dataType == 3">
        <div ng-repeat="option in question.choices " class="">
            <label for="mul__ques">
                <span ng-repeat="stAns in question.storedAnswer" ng-if="stAns == option.questionChoiceValue">
                    <input id="mul__ques" type="checkbox" ng-model="question.storedAnswer"   ng-change="onSelect(question, option);" />  
                </span>
            </label>
        </div>
    </span>

    <span name="multiSelectCheckBox" ng-if="question.dataType == 3">
        <div ng-repeat="option in question.choices  " class="">
            <label for="sin__ques">

                <input type="radio" id="sin__ques" 
                ng-model="question.storedAnswer" value=""  name="que_ques"  ng-change="onSelect(question, option);" />  

            </label>
        </div>
    </span>
</div>

I have an object like this:

[
    {
        "marked": "false",
        "questionId": "7d00a35ddb6313004f3bdde748961969",
        "helpText": "",
        "answered": "true",
        "storedAnswer": [
            1,
            5
        ],
        "questionSno": 1,
        "dataType": 3,
        "choices": [
            {
                "questionId": "7d00a35ddb6313004f3bdde748961969",
                "questionChoiceValue": 5,
                "questionChoiceText": "Float, long double"
            },
            {
                "questionId": "7d00a35ddb6313004f3bdde748961969",
                "questionChoiceValue": 4,
                "questionChoiceText": "Float"
            },
            {
                "questionId": "7d00a35ddb6313004f3bdde748961969",
                "questionChoiceValue": 3,
                "questionChoiceText": "float, double, long double"
            },
            {
                "questionId": "7d00a35ddb6313004f3bdde748961969",
                "questionChoiceValue": 2,
                "questionChoiceText": "long double, short int"
            },
            {
                "questionId": "7d00a35ddb6313004f3bdde748961969",
                "questionChoiceValue": 1,
                "questionChoiceText": "short int, double, long int, float"
            }
        ],
        "questionText": "In C, what are the various types of real data type (floating point data type)?",
        "selected": "false"
    },
    {
        "marked": "false",
        "questionId": "93e5c5e5db6713004f3bdde748961957",
        "helpText": "",
        "answered": "false",
        "storedAnswer": 1,
        "questionSno": 3,
        "dataType": 2,
        "choices": [
            {
                "questionId": "93e5c5e5db6713004f3bdde748961957",
                "questionChoiceValue": 3,
                "questionChoiceText": "May be"
            },
            {
                "questionId": "93e5c5e5db6713004f3bdde748961957",
                "questionChoiceValue": 2,
                "questionChoiceText": "False"
            },
            {
                "questionId": "93e5c5e5db6713004f3bdde748961957",
                "questionChoiceValue": 1,
                "questionChoiceText": "True"
            }
        ],
        "questionText": "A macro can execute faster than a function.",
        "selected": "false"
    }
]

enter image description here




Aucun commentaire:

Enregistrer un commentaire