4

我是 AngularJS 的新手,因此对如何将复选框或多选下拉列表绑定到单独的列表感到困惑。

<body ng-controller="FooListCtrl">
  <span ng-repeat="foolist in foos">
    <select ng-model="selected" ng-options="foo for foo in foolist" multiple="">
    </select>
  </span>
</body>
'use strict';

function FooListCtrl($scope) {
    $scope.foos = {"Bar": [ "foo", "bar"]};
    $scope.selected = [];
}

FooListCtrl.$inject = ['$scope'];

运行代码:http: //jsfiddle.net/gBcN2/

4

1 回答 1

2

如果我做对了你想要的:

  1. 你没有ng-app定义。
  2. No wrap - in <head>如果您使用 AngularJS 作为外部资源,则在 jsFiddle 上用于 AngularJS 片段的加载模式。
  3. 模型selected有它自己的“范围”,因为你使用ng-repeat. 要明白我的意思,这里是您的代码的固定版本:http: //jsfiddle.net/gBcN2/2/

第一个{{selected}}工作正常,但第二个是“超出”ng-repeat范围。

PS:如果你想像在你的例子中写的那样使用它,
你不必使用它:快速小提琴我会怎么做。ng-repeat

编辑:
对于复选框,它是这样的 - http://jsfiddle.net/qQg8u/2/

于 2013-05-20T08:30:03.527 回答