AngularJS дочерние вопросы спрятать и показать на основе ответов родительского вопроса - PullRequest
0 голосов
/ 28 января 2019

enter image description here

Дочерние вопросы необходимо скрыть, пока не будет выбран соответствующий родительский триггер ответа.Если этот ответ выбран, покажите дочерний вопрос.

У меня есть массив объектов, а также childrenQuestion объект в этом массиве, оба сравниваются по родительскому идентификатору с parentQuestionId

Вот так:

childrenQuestion: {id: 3, createdById: 1, updatedById: 1, assessmentId: 1, points: 2, …}  
id: 2  
question: "Do you take medication for hypertension?"

HTML часть:

<div ng-repeat="ques in parentQuestion" ng-init="f = ques">
                    <div class="health-text" >
                        <p ng-if="ques.parentQuestionId == NULL">{{ques.questionIndex}}. <span ng-if="ques.parentQuestionId != NULL">{{ques.childrenQuestion.subIndex}}</span>{{ques.question}}</p>
                        <select ng-model="selectedAns" class="form-control from-health" ng-if="ques.parentQuestionId == NULL" ng-change="getSubQuestion(ques.childrenQuestion)">
                            <option ng-if="ans.questionId == ques.id" ng-repeat="ans in assessAnswers" value="ans.answer">
                                {{ans.answer}}
                            </option>
                        </select>
                    </div>
                    <ng-include  src="'challengeTemplate.html'"></ng-include>
                    <!--<div ng-attr-id="{{ 'object-' + ques.id }}"></div>-->
                </div>

<script type="text/ng-template" id="challengeTemplate.html">
    <div ng-repeat="childrenQues in childerenQuestions" ng-show="f.id == childrenQues.parentQuestionId">
        <div class="health-text">
            <p ng-if="childrenQues.parentQuestionId != NULL">{{childrenQues.question}}</p>
            <select ng-if="childrenQues.parentQuestionId != NULL" ng-model="selectedAns" class="form-control from-health" ng-change="getSubQuestion(childrenQues.childrenQuestion)">
                <option ng-if="ans.questionId == childrenQues.id" ng-repeat="ans in assessAnswers" value="ans.answer">
                    {{ans.answer}}
                </option>
            </select>
        </div>
    </div>
    <div class="borderBottom" ng-if="!f.childrenQuestion"></div>
</script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...