我有一个关于结合所选小部件和 AngularJS 设置 ng-model 的问题(请参阅此视频:https ://www.youtube.com/watch?v=8ozyXwLzFYs )
我想做的是将收件人设置为一些将被预选的值。这是此示例的 HTML 和 JS(来自视频)
<h1>Chosen</h1>
<select data-placeholder="Choose a Recipient" multiple class="span4 chzn-select" chosen
ng-model="recipients" ng-options="recipient.name for recipient in recipientsList">
</select>
<p ng-repeat="recipient in recipients"><strong>{{recipient.name}}</strong></p>
和控制器中的 JS
$scope.recipientsList = [];
$scope.recipients = [];
$scope.fetchRecipients = function() {
$http.get($scope.url).then(function(result){
$scope.recipientsList = [
{"id":0, "name":"Recipient 0"},
{"id":1, "name":"Recipient 1"},
{"id":2, "name":"Recipient 2"},
{"id":3, "name":"Recipient 3"},
{"id":4, "name":"Recipient 4"},
{"id":5, "name":"Recipient 5"},
{"id":6, "name":"Recipient 6"},
{"id":7, "name":"Recipient 7"},
{"id":8, "name":"Recipient 8"},
{"id":9, "name":"Recipient 9"},
{"id":10, "name":"Recipient 10"}
];
$scope.recipients = [{"id":0, "name":"Recipient 0"},
{"id":1, "name":"Recipient 1"}];
});
}
$scope.fetchRecipients();
我尝试了一些组合,但菜单中的值没有预先选择,尽管它们存储在收件人中,因为它们在菜单下方可见。你可以在这里看到这个例子:http: //jsfiddle.net/YKZSw/8/
谢谢你的回答。
马泰