简体   繁体   English

如何使用Angular.js / Javascript正确删除特定行

[英]How to delete a particular row properly using Angular.js/Javascript

i need one help.I need to remove a particular row from a table using Angular.js .Here i have + and - button implementation.I have all my code inside https://plnkr.co/edit/D3UrDYwiglMKQyCW0wvW?p=preview 我需要一个帮助。我需要使用Angular.js从表中删除特定行。这里我有+-按钮实现。我将所有代码都放在https://plnkr.co/edit/D3UrDYwiglMKQyCW0wvW?p=preview中

From the Plunkr suppose for Monday i did 3 entries using + button.when i am deleting the middle(second) row using - button this is deleting but it doing null to the 3rd row subcategory field and also displaying the different subcategory which is not belongs to that row category part.Here i need when user will delete any row that row value will delete not other row.All codes are present inside plunkr .Please help me. 在周一的Plunkr中,我使用+按钮进行了3次输入。当我使用-按钮删除中间(第二条)行时,这正在删除,但它对第三行子类别字段执行了null,并且还显示了不属于的其他子类别到该行类别的一部分。在这里我需要用户何时删除任何行,该行值将删除其他行。所有代码都存在于plunkr中 。请帮助我。

I forked your plunker here 在这里分叉了你的朋克

Some of the changes: 一些变化:

  1. Defined listOfSubCategory in the controller as an array rather than having a function build it for each category. 在控制器中将listOfSubCategory定义为数组,而不是为每个类别创建函数。

Controller : 控制器

$scope.listOfSubCategory = [{
  id: 1,
  name: 'SubCategory 1',
  value: 1,
  category: 1
}, {
  id: 2,
  name: 'SubCategory 2',
  value: 2,
  category: 2
}, {
  id: 3,
  name: 'SubCategory 3',
  value: 3,
  category: 3
}, {
  id: 4,
  name: 'SubCategory 4',
  value: 4,
  category: 4
}];
  1. Changed ng-options to filter the subcategories based on selected category. 更改了ng-options以根据所选类别过滤子类别。

HTML 的HTML

ng-options="sub.name for sub in listOfSubCategory | filter:{ category: answer.category.id}"
  1. Also, made some other minor changes, like having only on for all 's rather than one for each and used "track by $index" where needed. 另外,还进行了其他一些小的更改,例如仅对all启用,而不对每个启用,并在需要时使用“按$ index跟踪”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM