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

AngularJS 單選框及多選框的雙向動(dòng)態(tài)綁定

 更新時(shí)間:2017年04月20日 09:49:45   作者:孫華強(qiáng)  
本篇文章主要介紹了AngularJS 單選框及多選框的雙向動(dòng)態(tài)綁定的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧

AngularJS 在 <input type="text" /> 中實(shí)現(xiàn)雙向動(dòng)態(tài)綁定十分簡(jiǎn)單,如下所示:

<input type="text" ng-model="topic.title" />

只需要用ng-model 與 $scope 中的屬性對(duì)應(yīng),即實(shí)現(xiàn)了type=”text” 的雙向動(dòng)態(tài)綁定。當(dāng) <input type="radio" /> 及 <input type="checkbox" /> 時(shí)情況略有不同:

1. <inputtype="radio" />

<input type="radio" name="person-action" value="go_home" ng-model="person.action" />回家 
<input type="radio" name="person-action" value="go_to_school" ng-model="person.action" />回學(xué)校 

通過 value 屬性指定選中狀態(tài)下對(duì)應(yīng)的值,并通過 ng-model 將單選框與 $scope 中的屬性對(duì)應(yīng),便實(shí)現(xiàn)了 type=”radio” 時(shí)的雙向動(dòng)態(tài)綁定。

2. <input type="checkbox" />

<input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_sound" />鈴聲 
<input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_vibrate" />震動(dòng) 
<input type="checkbox" ng-true-value="true" ng-false-value="false" ng-model="phone.play_lights" />呼吸燈 

通過AngularJS 的內(nèi)置指令 ng-true-value 和 ng-false-value ,指定多選框在選中和未選中狀態(tài)下對(duì)應(yīng)的值,再通過ng-model 將其與 $scope 中的屬性對(duì)應(yīng),便實(shí)現(xiàn)了type=”checkbox” 的雙向動(dòng)態(tài)綁定。

但是理想跟現(xiàn)實(shí)總是相差太多,在實(shí)際操作過程中還是出現(xiàn)了問題。應(yīng)該是ng-repeat中scope作用域的問題。

經(jīng)過一番搜索、調(diào)試,自己終于將此問題解決了,效果圖如下:

核心源碼

js

var str = ""; // 原來存放選中的項(xiàng) 
$scope.Selected = false; //默認(rèn)未選中 
var choseArr=[]; // 定義數(shù)組用于存放前端顯示 
$scope.check = function(z,x){ 
console.log("HUY:"); 
console.log(z); 
console.log("HUYU:"); 
console.log(x); 
if (x == false) { // 選中 
   str = str + z + ','; 
  } else { 
   str = str.replace(z + ',', ''); // 取消選中 
  } 
  choseArr = (str.substr(0,str.length-1)).split(','); 
 console.log("HY:"); 
 console.log(choseArr); 
 $scope.number_request = choseArr.length; // 前端顯示所選數(shù)量 
 $scope.content_request = choseArr; // 前端顯示所選請(qǐng)求ID 
}; 

Html

<tr ng-repeat="item in querydata"> 
<td ng-bind="$index+1">1</td> 
 <td><a ui-sref="#">{{item.postid}}</a></td> 
  <td>{{item.medname}}</td> 
  <td>{{item.medfact}}</td> 
  <td>{{item.medcnt}}</td>  
  <td>{{item.remark}}</td>   
  <td>{{item.tel}}</td>   
  <td>{{item.post_time}}</td> 
  <td><input id={{item.postid}} type="checkbox" ng-model="Selected" ng-click="check(item.postid,Selected)" /></td>   
</tr> 

參考文獻(xiàn):

http://www.fzitv.net/article/68155.htm

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

会同县| 始兴县| 静宁县| 衡东县| 高碑店市| 潍坊市| 巨野县| 石渠县| 合水县| 阿瓦提县| 通辽市| 天水市| 新巴尔虎右旗| 姚安县| 丰台区| 房产| 大名县| 保山市| 大余县| 木兰县| 布尔津县| 翁源县| 尼勒克县| 林州市| 达尔| 武汉市| 万年县| 巴塘县| 逊克县| 阿巴嘎旗| 四会市| 新田县| 建瓯市| 垫江县| 焉耆| 海阳市| 九寨沟县| 赞皇县| 建昌县| 天门市| 南和县|