角色新手,
我有这个:
<div ng-controller="Ctrl">
Sort by:
<select ng-model="voterList" ng-options="voter as voter.name for voter in voter.availableOptions">
</select>
<p>Ordered by: {{voterList.name}}</p>
和
var app = angular.module('app', []);
function Ctrl($scope) {
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
}
我需要将$ scope更改为$scope.voter.DoNotContactBefore
而不是$scope.voter
,但这似乎与ng-options混乱。我不知道我需要改变什么。
非常感谢,谢谢!
答案 0 :(得分:1)
我不确定我是否正确理解你的问题,但我觉得你只需要改写:
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
为:
$scope.voter = {
DoNotContactBefore: {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
]
}
};
然后只需将“ng-options”更改为ng-options="voter as voter.name for voter in voter.DoNotContactBefore.availableOptions"