我正在尝试做简单的事情:使用 AngularJS 将我的 JSON 对象列表放在表单上。我想将其中一个参数映射到 HTML 单选按钮控件。这是 HTML 模板:
<div ng-app="myApp" ng-controller='MainController'>
<div ng-repeat="channel in channels">
<p>Case {{ channel.schedule.timeOfDay }}</p>
<input type="radio" ng-model="channel.schedule.timeOfDay" ng-value="0" name="channel">Case 0</input>
<input type="radio" ng-model="channel.schedule.timeOfDay" ng-value="1" name="channel">Case 1</input>
<input type="radio" ng-model="channel.schedule.timeOfDay" ng-value="2" name="channel">Case 2</input>
<input type="radio" ng-model="channel.schedule.timeOfDay" ng-value="3" name="channel">Case 3</input>
<hr>
</div>
</div>
还有一个简单的控制器:
var app = angular.module('myApp', []);
app.controller('MainController', function ($scope) {
$scope.channels = [{
"id": 4,
"subject": null,
"body": "Votre utilisation de données a atteint (SMS) [Percentage]%",
"schedule": {
"dayOfWeek": 24,
"timeOfDay": 3,
"from": 1,
"to": 4
},
"channelType": 0
}, {
"id": 5,
"subject": null,
"body": "Votre utilisation de données a atteint (USSD) [Percentage]%",
"schedule": {
"dayOfWeek": 18,
"timeOfDay": 1,
"from": 0,
"to": 0
},
"channelType": 1
}, {
"id": 6,
"subject": "Avertissement",
"body": "Votre utilisation de données a atteint (E-Mail) [Percentage]%",
"schedule": {
"dayOfWeek": 33,
"timeOfDay": 3,
"from": 15,
"to": 22
},
"channelType": 2
}]
});
因此,如您所见,我将 channel.schedule.timeOfDay 映射到单选按钮控件,然后出现了奇怪的行为。单选按钮不反映第一个和第二个数组元素的值,而是反映第三个元素的值。有人请解释发生了什么吗?