2015-12-30 67 views
0

我正在第一次使用Angular JS进行开发,并且我创建了以下引导模态,其中有3个动态创建的div。一个div每次创建,它们是互斥的。下面是代码:动态创建的重置模态

<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <h4>User Menu</h4> 
     </div> 
     <div class="row"> 
      <!-- USER MENU 1 --> 
      <div ng-if="ctrl.state.current.name==='userMenu1'" ng-class="ctrl.fileOpen ? 'col-xs-8' : 'col-xs-12'" class="tablecontainer"> 
      <table class="table table-striped table-hover table-condensed"> 
       <colgroup> 
        <col class="col-md-1"> 
        <col class="col-md-2"> 
        <col class="col-md-2"> 
        <col class="col-md-3"> 
        <col class="col-md-2"> 
        <col class="col-md-2"> 
       </colgroup> 
       <thead> 
        <tr> 
         <th>&nbsp;</th> 
         <th>Firstname</th> 
         <th>Lastname</th> 
         <th>Address</th> 
         <th>Attachment</th> 
         <th>Group</th> 
        </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="user in users"> 
         <td> 
          <input type="checkbox" value="" ng-model="ctrl.checked[$index]" ng-disabled="ctrl.fileupload!==undefined" ng-change="ctrl.checkBox($index)" /> 
          </td> 
          <td>{{user.firstname}}</td> 
          <td> 
           <select class="form-control" ng-model="user.selectedAddress" ng-change="ctrl.checked[$index] = user.selectedAddress.destAddress" ng-options="o as o.destName for o in user.addresses"></select> 
          </td> 
         <td>{{user.selectedAddress.destAddress}}</td> 
         <td>{{ctrl.getFile($index)}}</td> 
         <td>{{ctrl.getGroup($index)}}</td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 

     <!-- USER MENU 2 DIV --> 
     [...] 

     <!-- USER MENU 3 DIV --> 
     [...] 

     <!-- BUTTONS PANEL DIV ---> 
     [...] 

      <div class="modal-footer"> 
       <button type="button" class="btn btn-default btn-flat" data-dismiss="modal">Close</button> 
      </div> 
    </div> 
</div> 

在每一个DIV用户可以输入一些文字填写,甚至通过按下几个按钮(我忘他们的代码)添加新的输入字段。 我希望每次用户关闭模式并再次打开模式时,模式会恢复到最初的div(menu1,menu2或menu3,取决于用户打开模式的位置)。

我该怎么做?

我尝试了几种方法(如thisthis),但没有人为我的情况。

回答

3

我改变了你的代码。你可以看到我的代码。

http://jsfiddle.net/deadmask92/8XCps/344/

我说:

function reset(){ 
    $('#myModal').modal('hide').remove(); 
    var myClone = myBackup.clone(); 
    $('body').append(myClone); 
} 

$('body').on('click','#myClose',reset); 

$('body').on('click','#CloseIcone',reset); 

和我改变:

$('body').on('click','#myReset',reset); 
+0

您已经测试了吗? 3个按钮也是这样做的... – smartmouse

+0

我测试过了!如果您在用户关闭模式时必须重置模式,则该模式是正确的。但我不明白你的问题。 –

+0

代码中的“关闭”和“重置”按钮有什么区别? – smartmouse