目标是进行一个包含 N 个问题和 N 个问题选项的调查。
我正在尝试对问题进行分组,然后将每个单选按钮与 ng-model 及其值区分开来,以获得一个对象
JSON
[ {“IdQuestion”:“5de05514fcfabc3354229e39”,“idSurvey”:“5ddf18d4fcfabd0ab05e1df4”,“titleQuestion”:“Porque compras?”,“IdQuestionOption”:“5de05551fcfabc3354229e3c”,“idSurveyQuestion”:“5de05514fcfab”选项" }, { "IdQuestion": "5de05514fcfabc3354229e39", "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion": "Porque compras?", "IdQuestionOption": "5de05555fcfabc3354229e3d", "idSurveyQuestion": "33option": "5de0525e44" "Salud" }, { "IdQuestion": "5de05514fcfabc3354229e39", "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion": "Porque compras?", "IdQuestionOption": "5de05558fcfabc3354229e3e", "idSurveyQuestion": "5de05514fcfabc3354229e39", "option": "Costumbre" }, { "IdQuestion" : "5de0552bfcfabc3354229e3a", "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion": "Como escuchaste del producto?", "IdQuestionOption": "5de0555dfcfabc3354229e3f", "idSurveyQuestion": "5de0552bfcfabc3354229e3a", "option": "Tv" }, { "IdQuestion": "5de0552bfcfabc3354229e3a", "idSurvey”:“5ddf18d4fcfabd0ab05e1df4”,“titleQuestion”:“Como escuchaste del producto?”,“IdQuestionOption”:“5de05563fcfabc3354229e40”,“idSurveyQuestion”:“5de0552bfcfabc3354229e3a”,“选项”:“收音机”},{ 5de0552bfcfabc3354229e3a", "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion": "Como escuchaste del producto?", "IdQuestionOption": "5de0556efcfabc3354229e41", "idSurveyQuestion": "5de0552bfcfabc3354229e3a", "option": "Diario" }, { " IdQuestion": "5de05548fcfabc3354229e3b", "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion": "Cada cuando consumes?", "IdQuestionOption": "5de05579fcfabc3354229e42", "idSurveyQuestion": "5de05548fcfabc3354229e3b", "option": "Diario" }, { "IdQuestion": "5de05548fcfabc3354229e3b", "idSurvey “:“5ddf18d4fcfabd0ab05e1df4”,“titleQuestion”:“Cada cuando 消费?”,“IdQuestionOption”:“5de0557dfcfabc3354229e43”,“idSurveyQuestion”:“5de05548fcfabc3354229e3b”,“选项”:“Semanal”},“IdQuestion”:“Idfcfabc3358” , "idSurvey": "5ddf18d4fcfabd0ab05e1df4", "titleQuestion”:“Cada cuando 消费?”,“IdQuestionOption”:“5de05582fcfabc3354229e44”,“idSurveyQuestion”:“5de05548fcfabc3354229e3b”,“option”:“Mensual”}]
功能 - 控制器
$scope.Survey_Read_Antive = function () {
$http.get("/API/Survey_Read_Antive").then(function (response) {
$scope.data_survey = response.data;
if ($scope.data_survey != "") {
$http.get("/API/Question_Read", { params: { idSurvey: $scope.data_survey.Id } }).then(function (response) {
$scope.data_Question = response.data;
$scope.hide_Survey_Answer = false;
$scope.hide_Survey_Answer_Enty = true;
});
} else {
$scope.hide_Survey_Answer_Enty = false;
$scope.hide_Survey_Answer = true;
}
});
}
HTML
<section class="row">
<div class="col-md-12 text-center">
<h3>PRODUCTO <b>{{data_survey.product | uppercase }}</b></h3>
</div>
</section>
<section class="row">
<div class="col-md-12">
<h5><b>Descripción</b> {{data_survey.descriptionSurvey}}</h5>
<br />
</div>
</section>
<section class="row">
<div class="col-md-12">
<form name="Form">
<section class="row" ng-repeat="data in data_Question">
<div class="col-md-6">
<p>{{data.titleQuestion}}
</div>
<div class="col-md-6">
<label class="radio-inline">
<input type="radio" value="{{$index+1}}" ng-model='currentQuantity["id" + data.titleQuestion]' required> {{data.option}}
</label>
</div>
</section>
<hr />
<div class="row">
<div class="col-md-2 col-md-offset-10">
<button class="form-control btn btn-info input-sm" ng-click="Survey_Save(data_survey.Id)" ng-hide="hide_Save">Finalizar</button>
</div>
</div>
</form>
</div>
</section>
看法
我想达到这个
IDE