[英]Can not set row value from table into array using Angular.js or Javascript
[英]Can not remove the expected row from table using Angular.js
我有一個問題,我需要使用Angular.js從我的應用程序的表結構中刪除一行特定代碼,我的代碼位於下面的plunkr鏈接中。
在上面的代碼中為星期一創建3行並填充所需的數據,每行都應有所不同。使用-
按鈕刪除中間行,您可以檢查最后一行的子類別是否顯示錯誤。這是我的問題。如果我需要我正在刪除行數據應從數組中刪除的任何特定行,而其他行將與所選數據保持不變。請幫助我。
我編輯了您的朋克: https ://plnkr.co/edit/4okaCC ? p = preview
您的問題是在ng-repaet中使用$ index。 刪除中間行時,第三行的$ index更改,並且您引用了錯誤的類別。 我更改您的插件,以使用返回子類別取決於所選類別的函數:
$scope.getSubCategoryFor = function(answer) {
if(!answer.category) {
return [];
}
console.log(answer);
var result = $filter('filter')(subcategories, {id:answer.category.id});
console.log('result', result);
return result;
}
我在html中使用它:
<table>
<tbody>
<tr ng-repeat="answer in d.answers">
<td>
<select class="form-control" id="answer_{{$index}}_subcategory" name="answer_{{$index}}_subcategory" ng-model="answer.subcategory" ng-options="sub.name for sub in getSubCategoryFor(answer)">
<option value="">Select Subcategory</option>
</select>
</td>
</tr>
</tbody>
</table>
我希望這能幫到您
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.