[英]Bind checkbox or multi-select dropdown to array in AngularJS?
我是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/
如果我說對了你想要什么:
ng-app
定義。 No wrap - in <head>
AngularJS片段的jsFiddle上,將No wrap - in <head>
wrap-置於No wrap - in <head>
加載模式下。 selected
模型具有其自己的“范圍”,因為您使用ng-repeat
。 明白我的意思,這是您的代碼的固定版本: http : //jsfiddle.net/gBcN2/2/ 首先{{selected}}
可以正常工作,但是第二個是ng-repeat
范圍的“外部”。
PS:
如果要像在示例中編寫的那樣使用ng-repeat
則不必使用ng-repeat
: 快速了解我的操作方式。
編輯:
對於復選框,它類似於-http://jsfiddle.net/qQg8u/2/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.