我正在为一个人格测验的后端工作,用户可以发送不同性格的客栈名称,一些问题以及问题的替代答案。用户(希望)也能够设置每个角色从答案的不同选择中收集多少分。涉及的数组内部有一些数组,数组中有对象。设置表单以便在可选答案的不同点发送时出现问题。我得到一个"无法读取未定义的属性"当我尝试将点记录到控制台时。下面是代码:
<html lang="en" ng-app="backend">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<h1>points test</h1>
<div ng-controller="QuestionsController">
<ul class="paa-linje">
<form novalidate>
<li class="paa-linje" ng-repeat="things in pointsArr track by $index">
<input class="input" type="number" min="0" max="10" ng-model="thing.points" required placeholder="0"/>
</li>
<input type="submit" ng-click="personPoints(thing)" value="Submit">
</form>
</ul>
</div>
<script>
var app = angular.module('backend', [])
app.controller('QuestionsController', function($scope) {
$scope.pointsArr = [
{nbr: 0, points: ''},
{nbr: 1, points: ''},
{nbr: 2, points: ''}
];
$scope.personPoints = function(field) {
console.log("points = " + field.points);
for (var i = 0; i < $scope.pointsArr.length; i++) {
console.log("points = " + field.points);
};
};
});
</script>