angularjs實(shí)現(xiàn)table增加tr的方法
需求:
上面是一個(gè)table,運(yùn)用了
<tr ng-repeat="rule in formData.ruleList track by $index">
循環(huán)顯示?,F(xiàn)在的一個(gè)需求是:需要在每行添加一個(gè)字段,不過(guò)不能在同一行顯示,需要在下一行顯示。我首先想到了直接加個(gè),不過(guò)沒(méi)有辦法換行。在下面再加個(gè)也不行。只能依賴強(qiáng)大的angulajs,自定義指令。下面我們就開(kāi)始。
1 自定義指令
.directive( 'kbnTableRow', function($compile) { return { restrict : 'A', link : function(scope, element) { element.after('<tr>'); function expressDescHtml() { var detailHtml = '<td></td><td colspan="5">' + '<div ng-show="rule.type!==1">' + '<div class="col-xs-9 row">' + ' <input type="text" class="form-control" ng-model="rule.exprDesc"readonly ">' + '</div>' +'</div>' + '</td>'; return detailHtml; } }, templateUrl : 'libs/kbnTable/table_row/rule.html' }; });
2 rule.html是原來(lái)的里的內(nèi)容
<td class="form-control-static"> <div class="form-control-static">{{$index+1}}</div> </td> <td> <div class="form-control-static" ng-show="rule.type===1" style="text-align: -webkit-left;">   {{rule.rightVar.desc}}</div> <div ng-show="rule.type!==1"> <div class="col-xs-9 row"> <input type="text" class="form-control" ng-model="rule.rightVar.desc" readonly title="{{rule.rightVar.desc}}"> </div> <div class="col-xs-3 "> <button class="btn btn-warning" ng-click="showRightVar(rule,'rightVar')">設(shè)置</button> </div> </div> </td> <td class="form-control-static" ng-show="formData.execType == 't02'"> <div class="form-control-static" style="padding-top: 0;"> <input type="text" class="form-control" ng-model="rule.score" title="{{rule.score}}" /> </div> </td> <td class="td-button" style="padding-left: 0; padding-right: 1px;"> <button class="btn btn-danger" ng-click="del(rule)">刪除</button> <input type="hidden" ng-model="rule.enable" /> </td> <td class="td-button" style="padding: 8px 0;"> <button class="btn btn-danger" ng-click="disabledRule(rule, $event)"> <span ng-if="rule.enable == 0">啟用</span> <span ng-if="rule.enable == 1">禁用</span> </button> </td>
不需要改變,原來(lái)是什么,這里就寫(xiě)什么。
3 初始頁(yè)面里的tr循環(huán)部分,用我們新建的指令改寫(xiě):
<div class="row"> <div class="col-xs-12 row"> <h4 class="col-xs-12"> <b>表達(dá)式設(shè)置</b> </h4> </div> <div class="col-xs-12"> <div class="row"> <div class="col-xs-10"> <table class="table text-center"> <tr> <th ng-click="toggleAll()"> <i class="fa discover-table-open-icon" ng-class="{ 'fa-caret-down': formData.on, 'fa-caret-right': !formData.on }"> </i> </th> <th width="45px">序號(hào)</th> <th>左變量</th> <th>操作符</th> <th>右變量</th> <th width="75px" ng-show="formData.execType == 't02'">分值</th> <th colspan="2">操作</th> <th></th> </tr> <tbody> <tr ng-repeat="rule in formData.ruleList track by $index" kbn-table-row class="discover-table-row"></tr> </tbody> </table> </div> <div class="col-xs-1"> <button class="btn btn-info" ng-click="addRule()">新增</button> </div> </div> </div>
這樣就可以完成我們的初始要求,不過(guò)可以在上面稍微改動(dòng)下,會(huì)實(shí)現(xiàn)更棒的功能,下面一行可以自動(dòng)收縮:
以上這篇angularjs實(shí)現(xiàn)table增加tr的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- angularjs表格ng-table使用備忘錄
- AngularJS ng-table插件設(shè)置排序
- Angularjs+bootstrap+table多選(全選)支持單擊行選中實(shí)現(xiàn)編輯、刪除功能
- angularJs中datatable實(shí)現(xiàn)代碼
- AngularJS中table表格基本操作示例
- 詳解angularjs popup-table 彈出框表格指令
- 對(duì)比分析Django的Q查詢及AngularJS的Datatables分頁(yè)插件
- angularjs實(shí)現(xiàn)table表格td單元格單擊變輸入框/可編輯狀態(tài)示例
相關(guān)文章
AngularJS中的$watch(),$digest()和$apply()區(qū)分
這篇文章主要介紹了AngularJS中的$watch(),$digest()和$apply()區(qū)分,感興趣的朋友可以參考一下2016-04-04AngularJS select加載數(shù)據(jù)選中默認(rèn)值的方法
下面小編就為大家分享一篇AngularJS select加載數(shù)據(jù)選中默認(rèn)值的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02Facade Service暴露commands簡(jiǎn)化代碼邏輯提高可訪問(wèn)性組合性
在 Angular 應(yīng)用開(kāi)發(fā)中,使用 Facade Service 暴露 commands(命令)以及訂閱這些 commands 是一個(gè)常見(jiàn)的設(shè)計(jì)模式,本文將詳細(xì)介紹在 Facade Service 中如何實(shí)現(xiàn)這一目標(biāo),并深入探討相關(guān)細(xì)節(jié),以及通過(guò)實(shí)際示例進(jìn)行說(shuō)明2023-10-10Angular 2父子組件數(shù)據(jù)傳遞之@Input和@Output詳解(下)
這篇文章主要給大家介紹了關(guān)于Angular 2父子組件數(shù)據(jù)傳遞之@Input和@Output的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-07-07Angular @HostBinding()和@HostListener()用法
本篇文章主要介紹了Angular @HostBinding()和@HostListener()用法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03通過(guò)AngularJS實(shí)現(xiàn)圖片上傳及縮略圖展示示例
本篇文章主要介紹了通過(guò)AngularJS實(shí)現(xiàn)圖片上傳及縮略圖展示,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01