這篇文章將為大家詳細講解有關(guān)angular框架如何實現(xiàn)全選與單選chekbox,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
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é)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.rwnh.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文標(biāo)題:angular框架如何實現(xiàn)全選與單選chekbox-創(chuàng)新互聯(lián)
標(biāo)題URL:http://www.rwnh.cn/article38/dohgsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、用戶體驗、網(wǎng)頁設(shè)計公司、品牌網(wǎng)站設(shè)計、商城網(wǎng)站、網(wǎng)站改版
聲明:本網(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)