2016-12-31 5 views
0
その後、最終的には、テーブルとチェックボックスと Accordianを生成 $scope.roleAssigned変数scropeに設定されているAJAX経由でJSONを以下

私のPHPプログラミング・リターン:ボタンを今すぐ

$json2 = '{"status":"OK","data":[{"label":"Admin","id":1,"rights":[{"id":"1","label":"create","selected":"1"},{"id":"2","label":"update","selected":"0"},{"id":"3","label":"delete","selected":"0"},{"id":"4","label":"lists","selected":"0"}]}, 
{"label":"Normal User","id":2,"rights":[{"id":"1","label":"create","selected":"1"},{"id":"2","label":"update","selected":"1"},{"id":"3","label":"delete","selected":"1"},{"id":"4","label":"lists","selected":"0"}]}]}'; 

私は戻って同じデータを返送しますクリックJSONでPHPに渡すselectedフィールドは、誰かがチェックボックスをクリックしたかどうかを示しています。したがって、例えば{"id":"1","label":"create","selected":"1"}{"id":"1","label":"create","selected":"0"}

である可能性があります。チェックボックスをオンにすると、スコープアレイのキーを更新する角型はありますか?私は反復DOM(jQueryの方法)を生成したくありません。

HTML

<div class="dynamic" ng-repeat="role in roles | orderBy:sortType:sortReverse | filter:queryRoles "> 
        <div class="panel panel-default"> 
         <div class="panel-heading"> 
          <h2 class="panel-title text-center"> 
           <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse_{{role.id}}"> 
            {{role.label}} 
           </a> 
          </h2> 

         </div> 
         <div id="collapse_{{role.id}}" class="panel-collapse collapse"> 
          <div class="panel-body text-center"> 
           <table id="roles-table" class="table table-striped" align="center"> 
            <thead> 
             <tr> 
              <td>Droit</td> 
              <td>Action</td> 
             </tr> 
            </thead> 
            <tbody> 
             <tr ng-repeat="right in role.rights"> 
              <td>{{right.label}}</td> 
              <td> 
               <input data-rid="{{role.id}}" type="checkbox" ng-checked="right.selected == 1"> 
              </td> 
             </tr> 
            </tbody> 
           </table> 
          </div> 
         </div> 
        </div> 
       </div> 

可能であれば私に教えてください。

答えて

1

あなたは$親を利用することができます。$インデックスと$インデックス

<input data-rid="{{role.id}}" type="checkbox" ng-checked="right.selected == 1" ng-click="checkIt($parent.$index, $index, right.selected)"> 

$scope.checkIt= function(parentIndex, index, selected){ 
     selected = (selected === "1") ? "0" : "1"; 
     $scope.roles[parentIndex].rights[index].selected = selected; 
    }; 
+0

だから、一度、特定のキーが更新されます。ボタンをクリックすると、更新されたボタンを送信しますか? – Volatil3

+0

はい。スコープデータを更新しています。同じ$ scope.rolesオブジェクトを使用してデータを送信している場合は、必ず更新されたものを送信します。 –

関連する問題