2016-08-05 47 views
0

我想使用檢查列表ng-model將綁定選定的數據基於兩個動態值。 我的代碼是:ng模型使用兩個動態值

<div ng-repeat="individualFieldInfo in formInatiatingData"> 
     <div ng-repeat="individualListItem in individualFieldInfo.list" 
      <input type="checkbox" ng- model= 
    "userGivenData[individualFieldInfo.fieldName][individualListItem.value]"> 
       {{individualListItem}} 
      </div> 
</div> 

這裏,

userGivenData[individualFieldInfo.fieldName][individualListItem.value]" 

不workng。 我的JSON是:

$scope.userGivenData={ 

} 
$scope.formInatiatingData = [ 
    { 
     type:"checkList", 
     fieldName:"Fruit", 
     list : [ 
      { 
       id:1, 
       value:"mango" 
      }, 
      { 
       id:2, 
       value:"Banana" 
      }, 
      { 
       id:3, 
       value:"Jackfruit" 
      } 
     ] 
    } 
] 

對於單一的動態結合userGivenData [individualFieldInfo.fieldName]正在工作。但是,對於兩個動態值,它不起作用。 我正在尋找一種方式,其中,如果用戶選中一個複選框,將在userGivenData.fieldName.value

+0

檢查時需要綁定什麼值? –

回答

2

angular.module('myApp', []) 
 
.controller('MyController', function($scope){ 
 
    $scope.someComplex = { 
 
    someInnerObj: { 
 
     thisIsAProperty: 'withSomeValue' 
 
    } 
 
    }; 
 
    
 
    $scope.thing1 = 'someInnerObj'; 
 
    $scope.thing2 = 'thisIsAProperty'; 
 

 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 

 

 
<div ng-app="myApp" ng-controller="MyController"> 
 
    <pre>{{someComplex|json}}</pre> 
 
    <pre>{{someComplex[thing1][thing2]}}</pre> 
 
    <input type="text" ng-model="someComplex[thing1][thing2]"/> 
 
</div>

綁定在測試情況下這樣做的工作......你能輸出一些更多的數據對象值,就像我在這裏使用json過濾器和pre標籤所做的那樣。