最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Angular.JS中select下拉框設(shè)置value的方法

 更新時(shí)間:2017年06月20日 09:05:32   作者:實(shí)習(xí)小編嘿  
select 是 AngularJS 預(yù)設(shè)的一組directive。下面這篇文章主要給大家介紹了關(guān)于Angular.JS中select下拉框設(shè)置value的方法,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。

前言

本文主要給大家介紹的是關(guān)于Angular.JS中select下拉框設(shè)置value的相關(guān)內(nèi)容,非常出來供大家參考學(xué)習(xí),下面來一起看看詳細(xì)的介紹:

最近在系統(tǒng)中增加一個(gè)查詢的篩選條件,通過下拉框選取,用的是Angular常見的ng-options 指令:

<select id="selectDetectUnit" class="form-control" ng-model="detectUnits" ng-options="detectUnit.name for detectUnit in detectQueryFilters.detectUnits"> 
   <option value="">全部</option> 
</select> 

但是有個(gè)問題,ng-options指令僅僅設(shè)置了下拉框選項(xiàng)的text,而不是value,打印下拉框的內(nèi)容如下:

<option value="" class="">全部</option> 
<option value="0">董浜惠健凈菜</option> 
<option value="1">古里綠品公司</option> 
<option value="2">曹家橋物流公司</option> 
<option value="3">董浜農(nóng)服中心</option> 

value部分是自動(dòng)設(shè)置的0,1,2,3,并不是實(shí)際的id。

那么,Angualr js 怎樣設(shè)置下拉框的value呢?

網(wǎng)上查了一遍,結(jié)合自己的一點(diǎn)探索,找到了答案,類似于表格記錄的用法

<select id="selectDetectUnit" class="form-control" ng-model="filter.detectUnitId" > 
  <option value="">全部</option> 
 <option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="{{detectUnit.id}}">{{detectUnit.name}}</option> 
</select> 

打印下拉框的內(nèi)容如下:

<option value="">全部</option>        
<!-- ngRepeat: detectUnit in detectQueryFilters.detectUnits --> 
<option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="160101" class="ng-scope ng-binding">董浜惠健凈菜</option> 
<option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="160102" class="ng-scope ng-binding">古里綠品公司</option> 
<option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="160103" class="ng-scope ng-binding">曹家橋物流公司</option> 
<option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="160104" class="ng-scope ng-binding">董浜農(nóng)服中心</option> 
<option ng-repeat="detectUnit in detectQueryFilters.detectUnits" value="160105" class="ng-scope ng-binding">港南村7組</option> 

雖然option中多了一些屬性,看著有點(diǎn)復(fù)雜,不過value總算有了正確的值。

然后試著取值:

alert($scope.filter.detectUnitId); 

問題解決!

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論

包头市| 仙桃市| 巩留县| 泰顺县| 赤水市| 丰台区| 衡水市| 厦门市| 会宁县| 许昌县| 手游| 涪陵区| 庄河市| 西林县| 偏关县| 鄂州市| 白河县| 民和| 樟树市| 根河市| 扎囊县| 乐至县| 蕲春县| 德惠市| 普兰店市| 阿拉善右旗| 乌兰浩特市| 宁乡县| 彝良县| 临武县| 浑源县| 同心县| 剑阁县| 图们市| 连南| 洪湖市| 静海县| 望谟县| 大渡口区| 哈尔滨市| 灯塔市|