ng-repeat包含一个父列表对象和多个子列表对象

时间:2017-07-07 01:40:16

标签: angularjs angularjs-directive angular-ui-router angularjs-ng-repeat

编辑问题:

Please follow this link in this first add mark is for child row add and second add mark is for parent add. in this case when i tried to add first parent of child, the child of second parent also adding, as per my issue, it should not be like that.

我的问题是:

循环第二个列表后,我尝试添加内部行(单击+),但它也在第二个表中添加外部行(请参阅第一张图像以查看屏幕截图)。

请查看以下代码,

请参考以下图片获取jsp页面:

 <div ng-repeat = "constospopuptablemain in costosPopupTableMainList">
          <div class="col-md-11 col-sm-10 col-xs-10 table-responsive ingpopuptableres" style="float:left;">
       <table class="table table-fixed table-condensed table-striped table-bordered table-hover no-margin tablemarg">
        <thead class="evlhead ingpopuphead">
          <tr>

            <th class="evltablethcontreg">Detalle Producto</th>
            <th class="evltablethcontreg">Contidad</th>
            <th class="evltablethcontreg">Unidad de medida</th> 
            <th class="evltablethcontreg">Precio Compra(PC)</th> 
            <th class="evltablethcontreg">Precio Venta(PV)</th>
            <th class="evltablethcontreg">CVTAS</th>
            <th class="evltablethcontreg">Add/Remove</th> 

          </tr>
        </thead> 

        <tbody class="evltbodypopup">
         <tr ng-repeat = "costosmaintablerow in constospopuptablemain.costosMainTableRowList">  

          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.detalledeproducto"> </td>           
          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.contidad"></td>
          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.unidaddemedia"> </td>           
          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.pc"></td>
          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.pv"> </td> 
          <td ><input type="text" class="no-marginconreg" ng-model="costosmaintablerow.cvtas"> </td>
          <td ><div class="addrembtn"><input class="btnadd" type="button" value="+" ng-click = "addCostoRow(constospopuptablemain.row,$index)">
          <input class="btnrem" type="button" value="-" ng-click = "removeCostoRow(constospopuptablemain.row,$index)"></div></td>

         </tr>


        </tbody> 
       </table>

       </div> 
       <div style="float:left;"> 
        <button style="background-color: #FAF0E6;width: 68px;margin:55px 0px 0px 4px;font-size: 13px;">+&nbsp;Casto</button>
      </div>

       <div class="Promediodivcosto">
         <label>Promedio</label>&nbsp;&nbsp;<input type="text" class="tottextfldingpop">
       </div>
       <div class="CostoTotalpopdiv">
         <label>Costo Total</label>&nbsp;&nbsp;<input type="text" class="tottextfldingpop">
       </div>

       </div>

js file:

"$scope.costosPopupTableMainList.push($scope.getCostosMainRow(0,$scope.getCostosInternalRowList()));"

$scope.costosMainTableRowList.push($scope.getCostosInternalRowList());
        $scope.costosPopupTableMainList.push($scope.getCostosMainRow(0,$scope.costosMainTableRowList));

$scope.getCostosInternalRowList = function(){

        return costosInternalRows = {

                "detalledeproducto":"",
                "contidad":"",
                "unidaddemedia":"",
                "pc":"",
                "pv":"",
                "cvtas":""

        };

以下行添加内部行(子列表应该在点击+时重复一次。)

$scope.addCostoRow = function(f,e){
    $scope.costosPopupTableMainList[f].costosMainTableRowList.push($scope.getCostosInternalRowList());
}

please refer below image to better understanding

[请参考以下链接获取JSP代码] [3] 例如,

<div ng-repeat = "listObj1 in listObjParent">
 <div ng-repeat ="listObj2 in listObj1.listObjchild">

       <input type="text" ng-model = "listObj2"/> <button ng-click="addChilRow()">+</button>

  

对于上面的代码,如果父对象长度为2且子对象长度为1。   所以父对象将重复2次,并且子对象将在每个父对象中可用。

问题是,

如果我试图在第一个父对象的子对象中添加一个额外的行(动态输入类型元素) 它还在第二个父对象中添加。但不应该这样添加。 所以它意味着子对象的每个父对象都应该有不同的范围。

我希望你理解我的问题。

感谢。

0 个答案:

没有答案