這篇文章將為大家詳細講解有關(guān)angular框架如何實現(xiàn)全選與單選chekbox,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)專注于和順企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),商城網(wǎng)站定制開發(fā)。和順網(wǎng)站建設(shè)公司,為和順等地區(qū)提供建站服務(wù)。全流程按需開發(fā),專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
1)頁面內(nèi)容(靜態(tài)頁)
<ul class='list-inline my-list-inline'>
<li class="action-check" ng-class="{'active':allHasChoice}" ng-click="clicktarget(true,tmp,dataList)">
<li>中文名稱</li>
<li>英文名稱</li>
<li>申請人類型</li>
<ul>
<div class="list-data">
<table>
<tbody>
<tr ng-repeat="tmp in dataList track by tmp.idTell"
ng-class="{true:'active',false:''}[targetChoice[tmp.idTell]==true]"
ng-click="ctmlicktarget(false,tmp,dataList)"
>
<td>
<span class="choice-icon"></span>
<span class="company-name over-flow-handel-style" title="{{tmp.chineseName}}"
ng-bind="tmp.cineseName"></span>
</td>
<td>
<span class="english-name over-flow-handel-style" title="{{tmp.englishName}}"
ng-bind="tmp.englishName"></span>
</td>
<td>
<span class="english-name over-flow-handel-style" title="{{tmp.abbreviation}}"
ng-bind="tmp.abbreviation"></span>
</td>
</tr>
</tbody>
</table>2)js代碼
首先當(dāng)然有一個參數(shù)數(shù)組,用于經(jīng)營經(jīng)營渲染頁面:
$scope.dataList=[
{'chineseName':'百度科技','englishName':'baidukeji','abbreviation':'小度','idTell':'bd'},
{'chineseName':'小牛科技','englishName':'xiaoniukeji','abbreviation':'小牛','idTell':'xn'},
{'chineseName':'京東科技','englishName':'jdkeji','abbreviation':'小京','idTell':'xj'},
{'chineseName':'順風(fēng)科技','englishName':'sfkeji','abbreviation':'小風(fēng)','idTell':'xf'},
{'chineseName':'阿里科技','englishName':'alkeji','abbreviation':'小里','idTell':'xl'},
{'chineseName':'淘寶科技','englishName':'tbkeji','abbreviation':'小寶','idTell':'xb'},
{'chineseName':'天貓科技','englishName':'tmkeji','abbreviation':'小貓','idTell':'xm'}
];定義一個數(shù)組用于存儲,選中的選項
$scope.targetChoice=[];
定義一個很簡單的方法:用于操作單選,全選的效果實現(xiàn)
$scope.clicktarget=function(isAllChoiceBtn,tmp,dataList){
//isAllChoiceBtn:用于表示用戶點擊的是否是全選按鈕,tmp:是數(shù)據(jù)集合中的一個數(shù)據(jù)對象
var count=0;//記錄被選中的子選項的個數(shù)
//說明用戶點擊的不是“全選”按鈕
isAllChoiceBtn==false?(function(){
//當(dāng)前選項取反
$scope.targetChoice[tmp.idTell]=!$scope.targetChoice[tmp.idTell];
//遍歷數(shù)據(jù)集合,統(tǒng)計已經(jīng)被購中的單選項
angular.foreach(dataList,function(v,k){
$scope.targetChoice[v.idTell]&& count++;
});
//如果count等于數(shù)據(jù)集合得長度,說明所有的單選被購中
count==dataList.length && $scope.allHasChoice=true:$scope.allHasChoice==false;
})()
//說明點擊的"全選"按鈕
:(function(){
$scope.allHasChoice=!$scope.allHasChoice;//狀態(tài)取反
$scope.allHasChoice==false?
//說明取消全選
:angular.forEach(dataList,function(v,k){
$scope.targetChoice[v.idTell]=$scope.allHasChoice;
count=0;
})
//說明選中全選
:angular.forEach(dataList,function(v,k){
$scope.targetChioce[v.idTell]=$scope.allHasChoice;
count++;
});
})()
}關(guān)于“angular框架如何實現(xiàn)全選與單選chekbox”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
標(biāo)題名稱:angular框架如何實現(xiàn)全選與單選chekbox
文章分享:http://chinadenli.net/article12/phdigc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站制作、外貿(mào)建站、品牌網(wǎng)站制作、網(wǎng)站改版、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)