2016-05-05 9 views
0

Monaca、Onsen UI、AngularJSを使用してクロスプラットフォームアプリを構築しました。私は、項目のリストを持っているページで複数のラジオボタンの値をAngularJSのコントローラに送信

、以下のように作成されたラジオボタンのサブリストとそれぞれの私

view.html
<ul class="list"> 
    <li class="list__item" ng-repeat="checkItemDescription in data"> 
     <span class="list__item__line-height"><strong>{{checkItemDescription.checkitemdesc}}</strong></span> 

     <label class="radio-button" ng-repeat="option in checkItemDescription.options"> 
      <input type="radio" 
       name="option_question_{{option.fleetcheckitemid}}" 
       ng-model="option.fleetcheckid"> 
      <div class="radio-button__checkmark"></div> 
      {{option.checkvaluedesc}} 
     </label> 
    </li> 
</ul> 

内のリストは、私が欲しいように構築されて表示され、ユーザはラジオボタンをクリックしてラジオボタンを選択することができます。

ユーザーが項目のいずれかのラジオボタンのいずれかを選択した場合、私は「checkItemDescription」IDだけでなく、JSONオブジェクトに「をoption.fleetcheckid」の両方を保存する必要があります。アイテムのリストはどのような長さでもかまいません。各リストアイテムをJSONオブジェクトとして自分のデータベースに送る必要があります。私は「checkItemDescription」IDだけでなく、私のNG-モデルのみ場合の値

+0

ng-click = doSomething(checkItemDescription、fleetCheckId) 'のように、ng-clickを使用して両方の値を渡すこともできます。このメソッドの内部では、値をデータベースに送信します。または、ハッキーに気をつけなければ、ng-modelで隠れた入力を行うことができます。 '' – oooyaya

答えて

0

をoption.fleetcheckid」含まれている場合「をoption.fleetcheckid」ボット送るにはどうすればよい

目的を一度使用する場合は、ng-hideを使用し、変数$scope.InputSet、次にng-change$scope.InputSetというファンクションにtrueと設定し、必要なロジックを渡すことができます。

<ul class="list" ng-hide="inputSet"> 
    <li class="list__item" ng-repeat="checkItemDescription in data"> 
     <span class="list__item__line-height"><strong>{{checkItemDescription.checkitemdesc}}</strong></span> 

     <label class="radio-button" ng-repeat="option in checkItemDescription.options"> 
      <input type="radio" 
       name="option_question_{{option.fleetcheckitemid}}" 
       ng-model="option.fleetcheckid" 
       ng-change="funcToCall(checkItemDescription.id, option.fleetcheckitemid)"> 
      <div class="radio-button__checkmark"></div> 
      {{option.checkvaluedesc}} 
     </label> 
    </li> 
</ul> 

コントローラ

$scope.funcToCall = function(checkItemDescription.id, option.fleetcheckitemid){ 
    $scope.inputSet = true; 
    //Your logic... 
}; 

あなたはオプションを渡すと、それは

$scope.funcToCall = function(checkItemDescription.id, option){ 
    // no need to use ng-hide here 
    $scope.optionId = option.id; 
    //remove the option 
    delete option; 
    //Your logic... 
}; 

これは動作するはずです削除する必要がちょうどそのチェックボックスを削除する場合。

関連する問題