从angularjs ui下拉列表中删除项目(Removing items from an angularjs ui dropdown)

编程入门 行业动态 更新时间:2024-10-23 14:33:06
从angularjs ui下拉列表中删除项目(Removing items from an angularjs ui dropdown)

我目前正在尝试动态删除angular-ui下拉列表中的元素,但是下拉内容似乎“重置”到我想要删除的元素。

这是一个说明问题的探测器,您可以点击“外部移除”或其中一个下拉元素来触发这种现象。

http://plnkr.co/edit/y4myttDQBDUymJYQEfmL?p=preview

用于删除的代码:

$scope.remove = function(index) { $scope.items = $scope.items.splice(index,1); };

有谁知道我在这里做错了什么? 谢谢

I'm currently trying to dynamically remove elements from a angular-ui dropdown instance, but the dropdown contents seems to 'reset' to the element I want to remove.

Here's a plunker illustrating the problem, you can either click on 'external remove' or on one of the dropdown elements to trigger the phenomena.

http://plnkr.co/edit/y4myttDQBDUymJYQEfmL?p=preview

Code used to remove:

$scope.remove = function(index) { $scope.items = $scope.items.splice(index,1); };

Does anyone have an idea what I'm doing wrong here? Thanks

最满意答案

'splice'函数返回被删除的项。 只是用。

$scope.items.splice(index,1);

并且不要将项目设置为返回值。

the 'splice' function returns the item that is removed. Just use.

$scope.items.splice(index,1);

And don't set items to the return value.

更多推荐

本文发布于:2023-04-29 10:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   列表中   ui   angularjs   items

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!