gpt4 book ai didi

javascript - angular js或ionic中的动态下拉列表

转载 作者:行者123 更新时间:2023-11-30 11:57:20 25 4
gpt4 key购买 nike

$scope.AllCities = window.localStorage.getItem['all_cities'];
<div class="row">
<div class="col">
<div class="select-child" ng-options="citie.name for citie in AllCities"
ng-model="data.city">
<label>Select Child</label>
<select class="form-control">

<option value="" disabled selected style="display: none;">Please Select City</option>

</select>
</div>
</div>
</div>

我试图创建一个动态下拉列表,但它显示未定义这里是我的代码

最佳答案

动态类别列表显示。

        <div class="label_EventDetail" align="left">Category</div>
<select class="ion-input-select" ng-options="category.name for category in categorys" ng-model="selectedcategory" ng-change="callFunction(selectedcategory)">
<option value="">Select Category</option>
</select>
</div>

和那样的 $scope 变量

$scope.categorys = [{
"id": 1,
"name": "A",
"select": true
}, {
"id": 2,
"name": "B",
"select": true
}, {
"id": 3,
"name": "C",
"select": true
}, {
"id": 4,
"name": "D",
"select": true
}, {
"id": 5,
"name": "E",
"select": true
}, {
"id": 6,
"name": "F",
"select": true
}, {
"id": 0,
"name": "G",
"select": true
}];

//调用方法是

    $scope.callFunction = function(data) {
console.log(data);
//you selected any data from list show in console.
}

当我从列表中选择任何一个时调用上面的代码 ng-change 事件

ng-change="callFunction(selectedcategory)"

并且 callFunction 不是必需的(它取决于用途)。

然后您从 selectedcategory 变量中获取选定的数据。

关于javascript - angular js或ionic中的动态下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37564723/

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