0

嗨,我这样做是为了添加动态表单字段

    <div ng-repeat="wspVdcMuniTbl in wspVdcMuniTbls">
        <div class="col-sm-5">
            <label>VDC/Municipalities</label>
            <select 
              ng-model="wspVdcMuniTbl.tbl_vdc_municipality_id[$index]" 
              options="municipalities"
              ng-options="municipality.id as municipality.name for municipality in municipalities">
            </select>
        </div>

        <div class="col-sm-5">
            <label>Wards</label>
            <input type="text"
                ng-model="wspVdcMuniTbl.wards[$index]"
                id="Location">
        </div>

        <div class="col-sm-2">
            <label>&nbsp;</label>
            <button ng-hide="$first" ng-click="removeServiceArea($index)">-</button>
        </div>

</div>

<div class="col-sm-2">
 <button ng-click="addServiceArea()">+</button>

我的js部分是

$scope.wspVdcMuniTbls = [{}];  
  $scope.addServiceArea = function(){        
        $scope.wspVdcMuniTbls.push({});
    }

    $scope.removeServiceArea = function(index){
        $scope.wspVdcMuniTbls.splice(index,1);
    }

此处添加动态表单字段工作正常,但提交后 console.log($scope.wspVdcMuniTbl) 未定义会出现什么问题,请帮忙

4

0 回答 0