删除数组元素时,边栏关闭
Sidebar closes when deleting element of array
我正在使用移动angular ui来打开和关闭侧边栏。在这个侧边栏中,用户可以搜索人员,并从数组中添加或删除这些人员。
我有这个重复显示人员数组,当单击<a ...></>
时,它关闭了侧边栏:
<li ng-repeat="recipient in persons.recipients">
<span class="wrapper">
<span class="imageWrap">
<span class="initials">
{{recipient.firstName.charAt(0)}}{{recipient.lastName.charAt(0)}} </span>
</span>
<a href="" class="trash" ng-click="removeRecipient($index);"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
<span class="details">
<span class="info">
{{recipient.firstName}} {{recipient.lastName}}
<span class="persnr">{{recipient.employeeID}}</span>
</span>
</span>
</span>
</li>
上面的html片段来自侧栏中的一个指令。removeRecipient($index);
函数如下所示:
$scope.removeRecipient = function(index) {
$scope.persons.recipients.splice(index,1);
}
函数工作,但关闭侧边栏,我不知道为什么它这样做。因此,每次用户删除收件人时,它都必须再次打开侧边栏。我如何保持这个边栏打开?
引用:
- 移动angularui: http://mobileangularui.com/docs/sidebars/
解决方案/strong>
我通过在removeRecipient($index);
函数后面的ng-click
中添加$event.stopPropagation();
来解决我的问题。
从doc中,有一行
你可以输入ui-turn-off='uiSidebarLeft'或ui-turn-off='uiSidebarLeft'在侧边栏内,使其在单击其中的链接后关闭。
所以你可以用这个或者你可以用或者你可以像下面这样用
e.stopPropagation()
在
中传递$event<a href="" class="trash" ng-click="removeRecipient($index,$event);"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
所以在代码中,你可以这样写。
$scope.removeRecipient = function(index,e) {
if(e){
e.stopPropagation()
}
$scope.persons.recipients.splice(index,1);
}
我没有使用相同的工具,但可能这是问题。
相关文章:
- 从组件状态的数组中删除元素
- Mongoose-在更新中删除数组元素
- 从数组中删除元素的最佳方法是:javascript/jquery
- 一些元素没有从数组中删除
- 从角度数组中删除元素
- 删除仅空格数组元素
- 正在从元素可能不同的数组中删除重复的元素
- 使用 V8 从密集数组中删除元素的最佳方法是什么
- 根据成员属性从数组中删除元素
- 如何从数组中删除元素
- 从数组中删除元素,然后保留其状态以备将来使用,而不使用全局变量
- 删除数组元素并将它们添加回原来的位置
- AngularJS/JavaScript从Localstorage数组中删除特定元素
- 正在从ReactJS数组中删除Stateful元素
- 删除基于另一个数组的数组元素
- 如何从数组中删除元素
- 取消选择下拉项时从数组中删除元素
- 如果一个键匹配,如何删除数组元素
- 从AngularJS中的数组中删除元素时出错
- 通过与猫鼬中的不同数组匹配,从嵌入数组中删除元素