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

angularjs實現(xiàn)table增加tr的方法

 更新時間:2018年02月27日 14:57:18   作者:hello-friend  
下面小編就為大家分享一篇angularjs實現(xiàn)table增加tr的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

需求:

上面是一個table,運用了

<tr ng-repeat="rule in formData.ruleList track by $index">

循環(huán)顯示?,F(xiàn)在的一個需求是:需要在每行添加一個字段,不過不能在同一行顯示,需要在下一行顯示。我首先想到了直接加個,不過沒有辦法換行。在下面再加個也不行。只能依賴強大的angulajs,自定義指令。下面我們就開始。

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是原來的里的內(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;">&nbsp&nbsp&nbsp{{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>

不需要改變,原來是什么,這里就寫什么。

3 初始頁面里的tr循環(huán)部分,用我們新建的指令改寫:

<div class="row">
   <div class="col-xs-12 row">
    <h4 class="col-xs-12">
     <b>表達式設(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">序號</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>

這樣就可以完成我們的初始要求,不過可以在上面稍微改動下,會實現(xiàn)更棒的功能,下面一行可以自動收縮:

以上這篇angularjs實現(xiàn)table增加tr的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Angular.js數(shù)據(jù)綁定時自動轉(zhuǎn)義html標簽及內(nèi)容

    詳解Angular.js數(shù)據(jù)綁定時自動轉(zhuǎn)義html標簽及內(nèi)容

    本篇文章主要介紹了詳解Angular.js數(shù)據(jù)綁定時自動轉(zhuǎn)義html標簽及內(nèi)容 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • 詳解Angular系列之變化檢測(Change Detection)

    詳解Angular系列之變化檢測(Change Detection)

    這篇文章主要介紹了詳解Angular系列之變化檢測(Change Detection),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • 最新評論

    合川市| 定襄县| 博湖县| 伊吾县| 墨竹工卡县| 宜昌市| 略阳县| 桃园县| 双城市| 中方县| 扎鲁特旗| 平武县| 峨边| 普兰县| 余庆县| 东明县| 惠来县| 五大连池市| 双桥区| 米泉市| 突泉县| 晋江市| 鄂托克前旗| 闽清县| 太原市| 独山县| 永安市| 巴塘县| 恭城| 麻栗坡县| 浦北县| 东丽区| 江川县| 临沂市| 精河县| 同心县| 东港市| 衡东县| 大邑县| 庆云县| 永和县|