gpt4 book ai didi

html - 如何在 AngularJS 中使用 ng-options 和 ng-init

转载 作者:行者123 更新时间:2023-11-28 16:13:48 25 4
gpt4 key购买 nike

我有如下格式的对象。如何在下拉列表中显示所有 ProjectID 并且用户可以选择任何一个值?请给我一个例子。

[
{
"ProjectManagerID": 4,
"ProjectID": 4,
"ResourceID": 4,
"Deleted": false
},
{
"ProjectManagerID": 5,
"ProjectID": 8,
"ResourceID": 5,
"Deleted": false
},
{
"ProjectManagerID": 6,
"ProjectID": 9,
"ResourceID": 6,
"Deleted": false
},

最佳答案

angular.module("myApp", [])
.controller("myController", ['$scope',
function($scope) {
$scope.options = [{
id: 1,
name: "Value to show user"
}, {
id: 2,
name: "some other value"
}];

$scope.optionValue = '';
}
])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp">
<div ng-controller="myController">
<select ng-model="optionValue" ng-options="opt.id as opt.name for opt in options">
<option value="">Please select a value</option>
</select>
</div>

</div>

关于html - 如何在 AngularJS 中使用 ng-options 和 ng-init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915447/

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