2017-06-16 69 views
1

當表內表在表內動態重複時ng-if不起作用當我在子表中添加一行時,在錯誤的父索引中使用index.am這樣的,但在輸入提起工作正常,但是當按鈕不起作用NG-如果條件採取錯誤的父索引ng-if使用ng-repeat嵌套表迭代時不起作用

如:

<div id="parentdivId" ng-repeat="parent in listOfParentTables"> 

      <table > 
      <thead class="evlhead ingpopuphead"> 
       <tr> 
       <th >A</th> 
       <th >B</th>    
       <th >C</th> 
       </tr> 
      </thead> 

      <tbody > 
      <tr ng-repeat="child in parent.childMaster" ng-if="child.status!=2"> 
      <td > 
       <select id="a10" ng-model="child.a10"> 
       <option ng-repeat="list in listMaster" value={{list.ID}}>{{list.NAME}}</option> 
       </select> 
       </td> 
      <td ><div class="addrembtn" ><input class="btnadd" type="button" value="+" id="addbutton10" ng-click="addNewChildRow($parent.$index,$index)"><input class="btnrem" type="button" value="-" id="deletebutton10" ng-click="removechildRow($parent.$index,$index)"></div></td> 
      </tr> 
       </tbody> 
      </table> 


      <div style="float:left;"> 
      <button class="parentbtn" style="margin:37px 0px 0px 17px !important;width: 75px;" value="AddTable" id="basebutton" ng-click="addNewParenttable($index)">+ &nbsp;Gasto</button> 
      </div> 
      <div style="float:left;"> 
      <button class="parentbtn" style="margin: 12px 0px 0px 17px !important;width: 75px;" value="AddTable" id="basebutton" ng-click="removeParenttable($index)">- &nbsp;Eliminar</button> 
      </div> 

      </div> 
+0

用ng重複顯示整個表格 –

+0

請參考我在https://stackoverflow.com/questions/20111636/index-of-object-in-array-while-using-ng-repeat-and-a-過濾器/ 37085767#37085767。它可能對你有所幫助 – Manas

+0

在上面的代碼中,當ng-if condtion被移除時它工作正常,但是我想把那個condion – Maxi

回答

2

在嵌套NG重複,在$指數不給數組中元素的索引被迭代。使用這樣的,

ng-click="addNewChildRow(listOfParentTables.indexOf(parent),parent.childMaster.indexOf(child))" 
ng-click="addNewParenttable(listOfParentTables.indexOf(parent))" 

的indexOf總是返回原來的指數在NG-重複 Plunker

希望它能幫助!

+0

謝謝你的回覆。我試試這個。 – Maxi

+0

它是如此工作? – Manas

+0

非常感謝:)高興地幫助 – Manas