2016-05-23 8 views
0

JSONファイルに入れ子オブジェクトがあり、JSONファイルの(動的)に基づいてチェックボックスを設定する必要があります。フィールドの名前、またはいくつの要素が存在するかを事前に知っておく必要があります。ここにサンプルがありますが、もっと子供がいるかもしれませんし、それぞれの子供はそこに多かれ少なかれアイテムを持つことができます。Angular-js - チェックボックスを設定してJSONファイルに基づいてトラッキングする

{ 
"Parent":{ 

"Child" : 

     { 
      "Child_01" : { 

       "description_01":false, 
       "description_02":false, 
       "description_03":false, 
       "description_04":false, 
       "description_05":false 
      }, 


      "Child_02" : 
       { 
       "something_01":false, 
       "something_02":false, 
       "something_03":false, 
       "something_04": false 
       }, 

       "Child_03" : 
       { 
       "things_01":false, 
       "things_02":false, 
       "things_03":false, 
       "things_04":false, 
       "things_05":false 
       } 

     } 

} 
} 

は今、私は(child_01、child_02、child_03 ....)、ダウンそれから、ドロップを移入する必要があり、ユーザーはそれらのいずれかを選択したときに、私はすべてのプロパティのチェックボックスを表示する必要があります。もちろん、選択したものを追跡することができます。

これは私が持っているものです。

$scope.children = response.data.parent.child; 
$scope.childrenList = []; 

angular.forEach($scope.children, function(value1, key1){ 
    $scope.childrenList.push(key1); 

}); 

とhtml:

<div ng-repeat="(key, data) in children"> 
       <input ng-model="childrenListModel" type="checkbox" name="{{child}}" value="{{child}}">{{child}}</input> 

</div> 

何も私がしようとするように動作しません。どんな助けもありがとう。

答えて

0

おそらく複数のネストされたng-repeatが必要です。この作業プランナーを見てください:http://plnkr.co/edit/K92JI7UlW9h6gh8SPeU5?p=preview

<div ng-repeat="child in children.Parent.Child"> 

    <div ng-repeat="options in child"> 

    <div ng-repeat="option in options"> 

     <div ng-repeat="(key, val) in option"> 

     <label for="{{key}}"> 
      {{key}} 
      <input name="{{key}}" type="checkbox" ng-model="option[key]" /> 
     </label> 


     </div> 

    </div> 
    <hr /> 

    </div> 

</div> 
+0

これは素晴らしいです、私はそれをすべて取得します。選択した子のプロパティのみを表示するには、どうすればドロップダウンを行うことができますか? – Ahoo

+0

2つの方法:(1) 'child in Child.Parent.Child'の代わりに、' child in getChild() 'を実行します。 getChild()は、選択した子の配列を返す必要があります。 (2)子のドロップダウンで、 'ng-model =" selectedChild "'を指定し、オプションドロップダウンでselectedChild "'で 'ng-options ="オプションを実行します。 – Kyle

+0

プランナーでオプション1を実行できるかどうか尋ねるのは余りにも難しいですか?でGetChildと1() – Ahoo

関連する問題