gpt4 book ai didi

AngularJS:多选预选选项

转载 作者:行者123 更新时间:2023-12-04 19:07:48 25 4
gpt4 key购买 nike

我正在尝试在我的多选中预选选项。为了说明我的情况,我做了一个 JSFiddle .

<select ng-model="properties" id="props" multiple 
ng-options="option.name group by option.category for option in options"></select>

不幸的是,我受到对象接收方式的限制,所以我想我需要 ng-options 属性。

有没有人知道我怎样才能得到“美国队长”和“博士”?加载时选择了“末日”?

最佳答案

尝试将您的 Controller 代码更改为:

   function TestCtrl($scope) {

var myOptions = [{
"id": "4",
"name": "Captain America",
"categoryId": "1",
"category": "Heroes"
}, {
"id": "5",
"name": "Iron Man",
"categoryId": "1",
"category": "Heroes"
}, {
"id": "10",
"name": "Magneto",
"categoryId": "2",
"category": "Vilains"
}, {
"id": "9",
"name": "Dr. Doom",
"categoryId": "2",
"category": "Vilains"
}];

$scope.options = myOptions;


$scope.properties = [myOptions[0], myOptions[3]];
}

说明:您将选择的选项(属性)设置为与构成完整列表的对象不同的实例。使用与上图相同的对象引用。

关于AngularJS:多选预选选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com