我在表单中使用radiolist并需要更新选项的数量。我以这种方式在控制器中加载radiolist:
//Initialize radiolist for answers
$scope.answersList = [];
$scope.answerSelected = $scope.selectAnsweredSurvey();
for (var i=0; i<$scope.answersCount; i++) {
$scope.answersList.push({value: $scope.answers[i].id, text: $scope.answers[i].text});
}
我的html格式的radiolist:
<div class="form-group" style="margin-top: 10px;">
<span style="100%"
data-editable-radiolist="answerSelected"
e-ng-options="s.value as s.text for s in ::answersList track by s.value"
e-title="answer.text"
e-ng-disabled="answeredSurvey(survey.id) || !survey.activa">
>
</span>
</div>
此外,我还有一个“监视器”来检测$ scope.answers的值何时发生变化并返回以使下一个内部显示:
for (var i=0; i<$scope.answersCount; i++) {
$scope.answersList.push({value: $scope.answers[i].id, text: $scope.answers[i].text});
}
但是radiolist选项不会更新。 感谢
答案 0 :(得分:1)
从此行中删除double ::它用于单向绑定,如果日期在控制器中得到更改,它将不会在视图中反映出来。注意e-ng-options="s.value as s.text for s in answersList track by s.value"
答案 1 :(得分:0)
从您的回答中不清楚您使用radiolist指令得到了什么,但您是否考虑过使用基本的单选按钮?
例如:
System.Xml.XPath
这不需要$ watch,也不会依赖某些指令。
已修改为在评论中建议使用ng-value over value
答案 2 :(得分:0)
接下来解决我的问题。
首先,我调整了我的xeditable表单,如@Sam Bartlett建议但
我的控制器:
//Initialize radiolist for answers
$scope.answerSelected = null;
$scope.answersList = [];
for (var i=0; i<$scope.respuestasCount; i++) {
$scope.answersList.push({value: $scope.answers[i].id, text: $scope.answers[i].text});
}
//watch for answers
$scope.$watch('answers', function watcher(valueNew, valueOld) {
if (valueNew !== valueOld) {
var answersCount = $scope.answers.lenght;
$scope.anwersList = [];
for (var i=0; i<answersCount; i++) {
$scope.answersList.push({value: $scope.answers[i].id, text: $scope.answers[i].text});
}
}
});
我对于radiolist的html:
<div class="form-group" style="margin-top: 10px;">
<div class="input" ng-repeat="answer in answersList">
<input type="radio"
name="answersSurvey"
ng-model="$parent.answerSelected"
ng-value="answer.value"
ng-disabled="answeredSurvey(survey.id) || !survey.active"
>
<label>{{answer.text}}</label>
</div>
</div>