2015-12-30 68 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