gpt4 book ai didi

javascript - Angular UI 选择点击删除项目

转载 作者:搜寻专家 更新时间:2023-11-01 04:15:41 25 4
gpt4 key购买 nike

我正在使用 UI-Select ,我注意到单击任何标签都会使它们变成蓝色,这对我想做的事情没有任何意义。如果单击,我希望将它们删除。经过检查,我注意到一个“x”触发了以下内容:

ng-click="$selectMultiple.removeChoice($index)"

经过一些挖掘,我找到了触发它的模板,它是“match-multiple.tpl.html”。我将 ng-click 复制到输入中,使其如下所示。

<span class="ui-select-match">
<span ng-repeat="$item in $select.selected">
<span
class="ui-select-match-item btn btn-default btn-xs"
tabindex="-1"
type="button"
ng-disabled="$select.disabled"

ng-click="$selectMultiple.removeChoice($index)"
ng-class="{'btn-primary':$selectMultiple.activeMatchIndex === $index, 'select-locked':$select.isLocked(this, $index)}"
ui-select-sort="$select.selected">
<span class="close ui-select-match-close" ng-hide="$select.disabled" ng-click="$selectMultiple.removeChoice($index)">&nbsp;&times;</span>
<span uis-transclude-append></span>
</span>
</span>
</span>

这破坏了标签系统(见图片) enter image description here

编辑 - 尝试了以下操作,错误消失但点击没有执行任何操作。

        ng-click="$selectMultiple.activeMatchIndex.removeChoice($index)"

如何将 ng-cick 附加到 标签 而不是“X”?

最佳答案

您的路线是正确的。我看不到您的完整代码(包括 Angular 代码),因此很难看出它为什么不起作用,但是 this Fiddle显示了一个工作示例 - 在 ui-select 中添加几个名称,然后单击名称上的任意位置(不仅仅是“x”)以将其删除。

ui-select配置如下:

  <ui-select multiple tagging ng-model="vm.selected" theme="bootstrap">
<ui-select-match placeholder="Pick one...">{{$item.value}}</ui-select-match>
<ui-select-choices repeat="val in vm.values | filter: $select.search track by val.value">
<div ng-bind="val.value | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>

以下代码使用自定义模板覆盖默认的“bootstrap/match-multiple.tpl.html”模板,该模板在父跨度上具有 ng-click 事件(就像您所做的那样)——请注意,已经有一个 ng-点击跨度 ng-click="$selectMultiple.activeMatchIndex = $index;",我不得不删除它并将其替换为 ng-click="$selectMultiple.removeChoice($index )” 。此代码块告诉 ui-select 使用此自定义模板而不是默认模板:

app.run(['$templateCache', function($templateCache) {
$templateCache.put('bootstrap/match-multiple.tpl.html',
'<span class="ui-select-match">' +
'<span ng-repeat="$item in $select.selected track by $index">' +
'<span ' +
'ng-click="$selectMultiple.removeChoice($index)" ' +
'class="ui-select-match-item btn btn-default btn-xs" ' +
'tabindex="-1" ' +
'type="button" ' +
'ng-disabled="$select.disabled" ' +
'ng-class="{\'btn-primary\':$selectMultiple.activeMatchIndex === $index, \'select-locked\':$select.isLocked(this, $index)}" ' +
'ui-select-sort="$select.selected">' +
'<span class="close ui-select-match-close" ng-hide="$select.disabled" ng-click="$selectMultiple.removeChoice($index)">&nbsp;&times;</span>' +
'<span uis-transclude-append></span>' +
'</span>' +
'</span>' +
'</span>');
}]);

关于javascript - Angular UI 选择点击删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30941141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com