如何允许在 ng-repeat 中使用 track by 重复并从控制器更新 ng-repeat 列表?
通过 $index 使用 track 我无法更新范围变量,但我想允许 ng-repeat 中的重复对象
条件:1)允许在 ng-repeat 中重复 2)使用 track by 3)从控制器更新 ng-repeat 列表
HTML
<div>
<ng-repeat="question in pagedata.questions track by $index">
<p>{{question.questionText}}<p>
<div ng-repeat="option in question.optionList track by $index">
<p ng-click="changeNextQuestion(question.nextQuestionId)">{{option}}</p>
</div>
</div>
控制器
$scope.pagedata.questions = [
{
"questionId" : 1
"questionText" : "A"
"optionList" : [A1, A2, A3],
"nextQuestionId" : 2
},
{
"questionId" : 2
"questionText" : "B"
"optionList" : [B1, B2, B3],
"nextQuestionId" : 2
},
{
"questionId" : 3
"questionText" : "C"
"optionList" : [C1, C2, C3],
"nextQuestionId" : 2
}
];
$scope.pagedata.questionsBack = angular.copy($scope.pagedata.questions);
$scope.changeNextQuestion = function(nextQuestionId){
var nextQuestion = findNextQuestionIndex($scope.pagedata.questions, nextQuestionId);
$scope.pagedata.questions[0] = $scope.pagedata.questionsBack[nextQuestion];
});
//I want to update view with new value.
}
}