最新国产好看的视频,伊人天堂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à)值。下面跟著小編一起來(lái)看下吧

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é)校 

通過(guò) value 屬性指定選中狀態(tài)下對(duì)應(yīng)的值,并通過(guò) 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" />呼吸燈 

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

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

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

核心源碼

js

var str = ""; // 原來(lái)存放選中的項(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://m.fzitv.net/article/68155.htm

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

相關(guān)文章

最新評(píng)論

杂多县| 临城县| 金山区| 清水河县| 汾西县| 永州市| 晴隆县| 鹤岗市| 墨脱县| 上杭县| 铜鼓县| 鹤庆县| 固始县| 绩溪县| 法库县| 隆林| 赣榆县| 寿宁县| 颍上县| 承德县| 察哈| 龙陵县| 荆州市| 灯塔市| 青河县| 年辖:市辖区| 瓦房店市| 远安县| 青浦区| 靖边县| 喀什市| 南安市| 乌什县| 讷河市| 潮安县| 新源县| 宣城市| 临武县| 孟连| 读书| 孝感市|