入力フィールドを使用して動的テーブル行を作成しています。角度では、この$index
変数を使用して配列のインデックスにアクセスできます。今私の問題は、サブレベル配列があり、親配列のインデックスを取得する必要があることです。また、すべての行に削除ボタンがあります。また、アクセスするには親インデックスIDにアクセスする必要があります。
サンプルオブジェクト値は次のとおりです。
Object
items: Array [2]
0: Object
particular_name: "SAMPLE PARTICULAR TITLE"
child_label: Object
items: Array [3]
0: Object
1: Object
2: Object
$$hashKey: "object:13"
1: Object
particular_name: "SAMPLE PARTICULAR TITLE"
child_label: Object
items: Array [0]
$$hashKey: "object:41"
私のテンプレートにはこれがあります:
<!-- this is the parent array -->
<div ng-repeat="item in quoteHeader.items" class="row">
<!-- some codes here... -->
<!-- 2nd level array -->
<tr ng-repeat="item in quoteHeader.items[$index].child_label.items">
<!-- need to access the parent index ID here... But index ID here is the index of the 2nd level array-->
<button type="button" class="btn btn-danger" ng-click="removeParent($index)"><span class="fa fa-times"></span></button>
JS:
$scope.removeParent = function($index) {
console.log($index);
//$scope.quoteHeader.items[$index].splice($index, 1);
}
それぞれng-repeat
が、渡されたデータを使用して子スコープを作成します。を使用して、子データの親インデックスを取得する必要があり$parent
ます。お気に入り
<button type="button" class="btn btn-danger" ng-click="removeParent($parent.$index)"><span class="fa fa-times"></span></button>
ng-init
ディレクティブを使用する別の方法。例を見るだけ
<div ng-repeat="item in quoteHeader.items" class="row" ng-init="parentIndex = $index">
<!-- some codes here... -->
<!-- 2nd level array -->
<tr ng-repeat="item in quoteHeader.items[$index].child_label.items">
<!-- need to access the parent index ID here... But index ID here is the index of the 2nd level array-->
<button type="button" class="btn btn-danger" ng-click="removeParent(parentIndex)"><span class="fa fa-times"></span></button>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加