【发布时间】:2015-11-05 14:20:20
【问题描述】:
" 我是 angularjs 新手"
1- 场景描述:
- 我们正在做一些类似调查的事情,
- 许多问题,每个问题都包含许多答案,
- 问题及其答案使用 angularjs 从数据库自动呈现
- 当用户完成调查后,只需单击保存即可将选定的选项发布到服务器
2- 问题 :
- 使用“angularjs”我如何收集数组中的用户选择或将选择的选择发布到服务器。
代码:https://jsfiddle.net/6kxx2vLu/
===================== angularjs 和 HTML =====================
<div ng-app="massApp" ng-controller="massCtrl">
<ul>
<li ng-repeat="question in Questions">
<h1>{{question.questionAR}}</h1>
<ul>
<li ng-repeat="answerChoice in question.answerChoices">
<div ng-if="answerChoice.answerChoiceTypeId == '1' ">
<label for="elmnt{{question.questionId}}">
{{answerChoice.answerChoiceAr}}
</label>
<input type="radio" name="elmnt{{question.questionId}}" value="{{answerChoice.answerChoiceId}}" />
</div>
</li>
</ul>
</li>
</ul>
<input ng-click="saveAnswers()" type="button" value="Save" />
</div>
<script type="text/javascript">
(function () {
//------
var moCdataForTest = [{
"questionId": 20,
"questionAR": "How you Know Our Services?",
"surveyId": 12,
"qyestionAnswersTypeId": 1,
"answerChoices": [
{
"answerChoiceId": 1,
"questionId": 20,
"answerChoiceAr": "From web or Google Serach",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 2,
"questionId": 20,
"answerChoiceAr": "From Frind",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 3,
"questionId": 20,
"answerChoiceAr": "Newspaper ads",
"answerChoiceTypeId": 1,
}
]
},
{
"questionId": 21,
"questionAR": "What is your satisfaction level?",
"surveyId": 12,
"qyestionAnswersTypeId": 1,
"answerChoices": [
{
"answerChoiceId": 4,
"questionId": 21,
"answerChoiceAr": "Good",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 5,
"questionId": 21,
"answerChoiceAr": "Very Good",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 6,
"questionId": 21,
"answerChoiceAr": "Excellent",
"answerChoiceTypeId": 1,
}
]
},
{
"questionId": 23,
"questionAR": "What is Visit Rate?",
"surveyId": 12,
"qyestionAnswersTypeId": 1,
"answerChoices": [
{
"answerChoiceId": 4,
"questionId": 23,
"answerChoiceAr": "1Star",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 5,
"questionId": 23,
"answerChoiceAr": "2Star",
"answerChoiceTypeId": 1,
},
{
"answerChoiceId": 6,
"questionId": 23,
"answerChoiceAr": "3Star",
"answerChoiceTypeId": 1,
}
]
}]
//-------
var massApp = angular.module("massApp", []);
//-------
massApp.controller("massCtrl", function ($scope) {
$scope.Questions = moCdataForTest;
$scope.saveAnswers = function () {
alert('Data Saved');
}
});
//-------
})();
</script>
【问题讨论】:
标签: angularjs