2017-03-06 5 views
0

angularjsのチェックボックスから動的データを取得するにはどうすればよいですか?私はコードの下に使用しようとしているが、エラーを取得:Angularjsがチェックボックスから動的データを取得

TypeError: Cannot read property '0' of undefined

HTML

<tr ng-repeat="procForAcnts in procForAcnt"> 
        <td>{{procForAcnts[0]}}</td> 
        <td><input type="checkbox" ng-model="procNums[$index]" ng-change="test()" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td> 
        <td>{{procForAcnts[3]}}</td> 
        <td>{{procForAcnts[1]}}</td> 
        <td>{{procForAcnts[5]}}</td> 
        <td>{{procForAcnts[2]}}.00</td> 
        <td><center>--</center></td> 
        <td>{{procForAcnts[7]}}</td> 
        </tr> 

JS

$scope.test = function() { 
var len= $scope.procForAcnt.length; 
alert(len); //working 
for(i=0; i<len; i++){ 
alert($scope.procNums[i]); 
} 
} 
+0

あなたの変数 'procForAcnts'が –

+0

あなたは「procForAcnt」 – Mamun

答えて

0

をあなたはここに完全なコードを投稿していない、けれども。あなたがテストメソッドにパラメータを送ることだけお勧めします。

は交換してください:付き

<td><input type="checkbox" ng-model="procNums[$index]" ng-change="test()" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td> 

<td><input type="checkbox" ng-model="procNums[$index]" ng-change="test(procNums[$index])" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td> 

を次にパラメータとして、あなたの試験方法で値を受け取る:

$scope.test = function(selectedValue) { 
    alert(selectedValue); 
}; 

それが助け場合は私に知らせてください!

+0

感謝のためのサンプルデータを提供することができます定義されますが、解決策http://stackoverflow.com/questions/14514461/how-do-i-bind-toを得ていることを確認-list-of-checkbox-values-with-angularjs –

+0

ええ、それは確かによく説明されています。それはすべてあなたのデザインの複雑さに依存します。ではごきげんよう! –

関連する問題