【问题标题】:how to clear the field when the ui-select is in a disabled state?当 ui-select 处于禁用状态时如何清除该字段?
【发布时间】:2016-09-29 15:17:28
【问题描述】:
您能告诉我如何清除该字段或删除处于禁用状态的字段吗?我在这个例子中使用 UI-select。每当用户选择 Nicole 时,我都会添加一个条件,它将取消选择 ui-select(用户无法再选择选项)。但我希望用户能够在禁用模式下清除/删除Nicole。
示例:如果用户错误地选择了Nicole 选项,那么他将无法选择任何其他选项。那么我可以在禁用状态下清除Nicole 选项吗?
Here is my plunker.
$scope.OnClickSelect = function(item) {
if (item.name === 'Nicole') {
if ($scope.multipleDemo.length > 0) {
$scope.multipleDemo.pop =[];
}
$scope.disabled = true;
}
$scope.multipleDemo.push(item.age);
}
【问题讨论】:
标签:
javascript
jquery
angularjs
angularjs-directive
ui-select
【解决方案1】:
问题不清楚。即使在选择“Nicole”之后,您是要启用 ui-select 还是只想清除 ng-model?
如果您想在用户意外选择“Nicole”时提供启用 ui-select 的选项,您必须保留一个复选框或任何设置 $scope.disabled = false; 的触发器
您的 OnClickSelect 方法还有 2 个问题。
我猜你正试图在用户选择“Nicole”时清除 ng-model,但 $scope.multipleDemo.pop =[]; 为数组 multipleDemo 创建了一个名为 pop 的新属性。如果要清除数组,请使用$scope.multipleDemo =[];
为什么只将 age 属性推入 multipleDemo 数组?如果您只想存储年龄属性,您可以在您的 ui-select 代码中使用以下语法
<ui-select-choices repeat="person.age as person in people | filter:$select.search">
{{person.name}}
</ui-select-choices>