angularjs copy:不放在表中的第二行

p3rjfoxz  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(411)

我有一个问题,我有一个困难的时间,我不知道我如何才能添加到第二行当我点击按钮时使用angularjs它总是在第一行,对不起我的英语。
这是我的模板

<div class="col-md-6" style="padding: 0px" ng-if="populateForm">

                    <div id="divGrid" class="dv well" ng-repeat="form in populateForm" ng-if="form.field_type == 'gridview'">

                        <div class="row clearfix">     
                          <div class="col-md-9"></div>
                          <div class="col-md-3" >
                               <button type="button"  ng-click="AddRow(form)" data="{{form.field_id}}"  id="AddBtn{{form.field_id}}" class="btn btn-success float-right btnCus"  >+</button>
                               <a  ng-click="removeRow($event)" id="RemBtn{{form.field_id}}" data="{{form.field_id}}" class="btn btn-warning float-right btnCus" ng-disabled="BtnDisable">-</a>
                          </div>
                            <div class="col-md-12 table-responsive " style="padding: 0 3px;" id="parent{{form.field_id}}" >
                                <table class="table table-bordered"  border="" cellpadding="" cellspacing="" style="background-color:white" id="parent{{form.field_id}}">
                                <thead>
                                  <tr >
                                   <th ng-repeat="gridDColumn in form.GridList">{{gridDColumn.field_title}}</th>
                                  </tr>
                                  </thead>
                                   <tbody>
                                     <tr>
                                     <td ng-repeat="gridData in form.GridList">

                                     <div ng-if="gridData.field_type == 'Textbox' && gridData.field_datatype == 'Text'">
                                      <div ng-if="gridData.field_required == 'True'">
                                       <div class="control-group has-feedback">
                                          <div class="Textbox">
                                           <div ng-if="gridData.enable_textformat == 'True'">
                                           <input id="sub{{gridData.field_id }}" name="textinput"   ng-model="gridData.value"   placeholder="{{gridData.field_textformat}}" type="text" ng-required="{{gridData.field_required | lowercase}} && {{gridData.field_standard | lowercase}} == true"   class="col-md-5 rectangle form-control"/>
                                           </div>
                                            <div ng-else>
                                           <input id="sub{{gridData.field_id }}" name="textinput"    ng-model="gridData.value"  type="text"  placeholder=""  ng-required="{{gridData.field_required | lowercase}} && {{gridData.field_standard | lowercase}} == true"  class="{{gridData.field_required}} col-md-5 rectangle form-control"/>
                                           </div>
                                          </div>
                                       </div>
                                      </div>
                                      <div ng-if="gridData.field_required == 'False'">                               
                                          <div class="control-group">
                                          <div class="Textbox">
                                             <div ng-if="gridData.enable_textformat == 'True'">
                                                <input id="sub{{gridData.field_id }}" name="textinput"  ng-model="gridData.value"   placeholder="{{gridData.field_textformat}}" type="text"  ng-required="{{gridData.field_required | lowercase}} && {{gridData.field_standard | lowercase}} == false" class="col-md-5 rectangle form-control"/>
                                             </div>
                                               <div ng-else>
                                             <input id="sub{{gridData.field_id }}" name="textinput"      ng-model="gridData.value"  type="text"  placeholder="" ng-required="{{gridData.field_required | lowercase}} && {{gridData.field_standard | lowercase}} == false" class="{{gridData.field_required}} col-md-5 rectangle form-control"/>
                                           </div>
                                          </div>
                                      </div>
                                     </div>
                                    </div>
                                        <div ng-if="gridData.field_type == 'Textbox' && gridData.field_datatype == 'Numbers'">
                                           <div ng-if="gridData.field_required == 'True'">
                                               <div class="control-group has-feedback">
                                                <div class="Textbox">
                                               <input id="sub{{gridData.field_id }}" name="textinput"  ng-model="gridData.value"  placeholder="numbers" type="text"   class="col-md-5 rectangle form-control numbersonly"/>
                                               </div>
                                               </div>
                                           </div>
                                               <div ng-if="gridData.field_required == 'False'">
                                               <div class="control-group">
                                                <div class="Textbox">
                                               <input id="sub{{gridData.field_id }}" name="textinput"  ng-model="gridData.value"   placeholder="numbers" type="text"   class="col-md-5 rectangle form-control numbersonly"/>
                                               </div>
                                               </div>
                                           </div>
                                            </div>
                                             <div ng-if="gridData.field_type == 'Textbox' && gridData.field_datatype == 'Date'">
                                              <div ng-if="gridData.field_required == 'True'">
                                               <div class="control-group has-feedback">
                                                <div class="Textbox">
                                               <input id="sub{{gridData.field_id }}" name="textinput"  ng-model="gridData.value"  placeholder="numbers" type="text"  datepicker-popup='dd/MM/yyyy' datepicker-options='dateOptions' is-open='openedGrid'  class="col-md-5 rectangle form-control"/>
                                               </div>
                                               </div>
                                           </div>
                                               <div ng-if="gridData.field_required == 'False'">
                                               <div class="control-group">
                                                <div class="Textbox">
                                               <input id="sub{{gridData.field_id }}" name="textinput"  ng-model="gridData.value"   placeholder="numbers" type="text"  datepicker-popup='dd/MM/yyyy' datepicker-options='dateOptions' is-open='openedGrid'  class="col-md-5 rectangle form-control"/>
                                               </div>
                                               </div>
                                           </div>
                                            </div>
                                              <div ng-if="gridData.field_type == 'dropdownList'">

                                              <div ng-if="gridData.field_required == 'True'">
                                               <div class="control-group has-feedback">
                                                <div class="dropdownList">                                           
                                                 <div  >
                                               <select id="sub{{gridData.field_id }}" ng-model="gridData.value"  class="form-control"  ng-required="true" >
                                                 <option value="" >(Select)</option>
                                              <option ng-repeat="dd in gridData.Newvalue" ng-value="dd.dd_value">
                                             {{dd.dd_text}}
                                               </option>
                                           </select>
                                                 </div>             
                                               </div>
                                             </div>
                                           </div>
                                               <div ng-if="gridData.field_required == 'False'">
                                               <div class="control-group">
                                                <div class="dropdownList">
                                                 <div >
                                                    <select id="sub{{gridData.field_id }}" ng-model="gridData.value"  class="form-control">
                                                    <option value="" >(Select)</option>
                                        <option ng-repeat="dd in gridData.Newvalue" ng-value="dd.dd_value">
                                        {{dd.dd_text}}
                                        </option>
                                     </select>
                                                 </div>

                                               </div>
                                               </div>
                                           </div>
                                            </div>
                                              <div ng-if="gridData.field_type == 'Checkbox'">
                                               <div class="Checkbox">
                                               <label id="sub{{gridData.field_id }} checkbox" style="font-weight:lighter;" >
                                               <label style="margin-left:-20px;display:none;"> {{gridData.field_desc}}</label>
                                                </br><input id="{{gridData.field_id }}" type='checkbox' class=" gridData.field_required "> 
                                               </label>
                                               </div>
                                               </div>
                                          </td>
                                      </tr>

                                   </tbody>
                                </table>
                            </div>
                        </div>                              
                     </div>   

                    </div>

我的控制器

$scope.AddRow = function (obj) {

                    var se = obj.GridList;
                    var appendValue = "";
                    $scope.counter = 0;
                    angular.forEach(se, function (vals) {

                        var _dat = angular.copy(vals);

                        console.log(vals);

                        se.push(_dat);
                    })
                    }

未单击按钮复制时的示例屏幕截图1。点击按钮时不点击图片截图2.输出点击按钮图片我是初学者我不知道具体要做什么它总是放在第一行而不是第二行。

rsl1atfo

rsl1atfo1#

$scope.AddRow = function (obj) {
    var gridData = obj.GridList;
    var appendValue = "";
    $scope.counter = 0;
    var last_row = _.last(gridData);
    console.log(last_row);
    if (last_row) {
        gridData.push(last_row);
    } else {
        gridData.push({
            title: null,
            name: null,
        });
    }
}

使用下划线并获取最后一行,然后直接推送,而不使用for-each循环。https://underscorejs.org/#last

相关问题