使用angularjs怎么實現動態獲取下拉框的值?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
js文件:
//職務等級和檔次/軍銜等級和檔次,需要從后臺獲取:poslist,type:2/3/4/5
$scope.getDyActivityInforItems=function(){
serviceData.getData('inforinput/getAllSelectValueByType','POST',{
type:2
}).then(function(json){
if(json.code==0){
$scope.poslist=json.content;
};
}, function(json){
console.log(json);
});
};界面:
<!-- 空格空開來區分職務等級 -->
<div class="item" >
<label class="list_tit">職務等級</label>
<div class="item_input" ng-init="getDyActivityInforItems()">
<!-- <select class="fillIn select-able" ng-model="item" ng-options="item as y for y in addInfo.posList" id="dutLevel_view_1" name="dutLevel">
</select> -->
<select class="fillIn select-able" ng-model="selectedPos" id="dutLevel_view_1" name="dutLevel">
<option ng-repeat="x in poslist" value="{{x.select_code}}">{{x.select_name}}</option>
</select>
<span class="imp_list_rema">*</span>
<!--
<select class="fillIn select-able" ng-model="addInfo.addInfoView.positionRank" >
<option value="" selected>請選擇</option>
</select> -->
</div>
</div>===============分割線,2017年7月20日17:07:14-============
后面遇到一個問題,當新增了一個下拉選項,需要刷新了下拉的list,但就會默認顯示第一個,沒有獲取剛開始顯示界面的值,需要使用apply進行更新:
addInfo.addInfoView.positionRank=0;
$scope.poslist=json.content;
setTimeout(function() {
$scope.$apply(function() {
addInfo.addInfoView.positionRank=yuanPos;
});
}, 1000);html上:
<!-- 空格空開來區分職務等級 -->
<div class="item" >
<label class="list_tit">職務等級</label>
<div class="item_input" ng-init="getPosMilSelectValue()">
<select class="fillIn select-able" ng-selected="addInfo.addInfoView.positionRank" ng-model="addInfo.addInfoView.positionRank" id="dutLevel_view_1" name="dutLevel">
<option ng-repeat="x in poslist" value="{{x.select_code}}">{{x.select_name}}</option>
</select>
<span class="imp_list_rema">*</span>
<span ng-click="addInfo.viewInput_add_item=!addInfo.viewInput_add_item;addInfo.addItemName='';selectType=2">
<a href="javascript:;" rel="external nofollow" title=""> + </a></span>
</div>
</div>關于使用angularjs怎么實現動態獲取下拉框的值問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。