2016-08-05 59 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标签所做的那样。