gpt4 book ai didi

javascript - 如何设置默认值以在 Angular JS 中选择选项

转载 作者:行者123 更新时间:2023-12-01 03:42:07 25 4
gpt4 key购买 nike

我有一个选择选项,并且必须选择默认选项,即选项[0],如何选择?。

{{ x.community_Type }}

我有方法从服务器接收响应。

$http.get("http://192.168.1.10:8080/apartment/community/type/list").then(function(response) {
$scope.myData = response.data.type;
$scope.log = {community_type_id : $scope.type[0].value}; //Not working
});

community_Type 数据来自网络服务:

    {
"type": [
{
"community_type_id": 19,
"community_Type": "Religious Institution",
"community_type_details": "To religious leaders"
},
{
"community_type_id": 20,
"community_Type": "Religious / Common Interest Group",
community_type_details": "To religious leaders"
},
{
"community_type_id": 21,
"community_Type": "Residential Society",
"community_type_details": "To religious leaders"
}
],
"status": "success",
"message": " community type list ."
}

最佳答案

尝试将默认值显示为选项[0]

ng-if="false" 将默认值显示为 option[0]

删除后,列表中的第一项将显示为空。

function optionController($scope) {
$scope.myData = [{
"community_type_id": 19,
"community_Type": "Religious Institution",
"community_type_details": "To religious leaders"
}, {
"community_type_id": 20,
"community_Type": "Religious / Common Interest Group",
"community_type_details": "To religious leaders"
}, {
"community_type_id": 21,
"community_Type": "Residential Society",
"community_type_details": "To religious leaders"
}]
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<div ng-controller="optionController">
<select ng-model="log.community_type_id" ng-options="x.community_type_id as x.community_Type for x in myData">
<option value="" ng-if="false">{{ x.community_Type }}</option>
</select>
</div>
</div>

关于javascript - 如何设置默认值以在 Angular JS 中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43801952/

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