2017-02-14 3 views
-3

私は意味のある名前を持つテキストボックスを持っていて、それぞれに対応するテキストボックスを持っている単純なフォームを持っています。チェックボックスの値と対応するテキストボックスの値を取得する角度の方法

私はチェックボックスとそのIDのリストを提案に従うことで取得できますが、対応するテキストボックスの値を取得できません。

これを達成するためのガイダンスはありますか? FYIでは、チェックボックスの値はデータベースからのものであり、ng-repeatによって反復されます。ここで

は、コードスニペットは、私が正しくあなたを理解していれば、あなたは

$scope.materialList.push({ 
    'materialId' : parseInt(materialId, 10), 
    'requiredQty' : $scope.itemList.find(x => x.inventoryId == materialId).requiredQty 
}); 

またはこの...これを試みることができるいずれか

<tr ng-repeat="item in itemList | filter:search_query"> 
    <td> 
    <label for="{{item.inventoryId}}"> 
    <input type="checkbox" class="checkbox-circle" 
    ng-click="materialSelected(materialSelection.ids, item.inventoryId);" 
    ng-model="materialSelection.ids[item.inventoryId]" name="group" id=" 
    {{item.inventoryId}}" /> {{item.itemName}} 
    </label> 
    </td> 
    <td><span> 
    <label> 
    <input type="text" class="form-control" ng-model="item.requiredQty">      
    </label></span> 
</td> 

Javascriptコード

$scope.materialSelected = function(idsList, inventoryId) { 
        $scope.materialList = []; 
        var materialId; 
        for (materialId in idsList) { 
         if (idsList[materialId] == true) { 
          $scope.materialList.push({ 
           'materialId' : parseInt(materialId, 10) 
          }); 
         } 
        } 
       } 
+0

、これをキャプチャする機能を追加する必要があなたはplsはあなたのコードスニペット –

+0

を表示することができますI私のポストにHTMLとJSのコードを追加しました。それを見てください。 – CrazyMac

+0

@CrazyMacこれはうまく動作する運がありましたか?他の方法で助けてもらえますか? –

答えて

0

、私は以下のコードを追加し、JSでは

<span ng-repeat="item itemList" style="text-align: left;"> 
<label for="{{item.itemID}}"> 
<input type="checkbox" class="checkbox-circle" ng-click="itemSelected(selection.ids, item.itemID)" style="border-radius: 2px;" ng-model="selection.ids[item.itemID]" name="group" id="{{item.itemID}}" /> {{item.itemName}} 
</label> 
</span> 

は、私が

function(idsList) { 
for (plantID in idsList) { 
    if (idsList[plantID] == true) { 
    } 
} 
} 
0

..です。

$scope.materialList.push({ 
    'materialId' : parseInt(materialId, 10), 
    'requiredQty' : $scope.itemList.filter(function(v) { return v.inventoryId == materialId; })[0].requiredQty 
}); 

必要なブラウザのサポートによって異なります。 HTML要素で

関連する問題