[英]How to dynamically disable ui-sortable directive in angular-ui
我使用angular-ui进行可排序使用ui-sortable指令。 是否可以根据范围状态动态启用/禁用可排序功能? 所以我需要一个按钮来改变范围属性的状态,并根据这个属性进行排序要么应该工作,要么不工作。
angular指令支持观察可排序选项何时更改:
scope.$watch(attrs.uiSortable, function(newVal, oldVal){
所以你要做的就是查看jqueryui可排序文档,并更新插件上的正确属性。
HTML
<ul ui-sortable="sortableOptions" ng-model="items">
<li ng-repeat="item in items">{{ item }}</li>
</ul>
<button ng-click="sortableOptions.disabled = !sortableOptions.disabled">Is Disabled: {{sortableOptions.disabled}}</button>
JS
app.controller('MainCtrl', function($scope) {
$scope.items = ["One", "Two", "Three"];
$scope.sortableOptions = {
disabled: true
};
});
您可以使用ui-if
在ui-sortable
版本和不可排序版本之间切换,但这是一个可怕的设计。 但是,如果你检查了jQuery可排序文档 ,似乎有一个disabled
选项。 如果指令当前正在查看选项对象以进行更改,则只需切换此选项即可。 如果通过引用而不是值来监视选项对象,那么也许您应该通过调整打开一个pull-request?
HTML
<div class="group-container" ui-sortable="vm.groupSortable" ng-model="group.groups">
JS
vm.groupSortable = {
connectWith: ".group-container",
disabled: true
};
vm.disableDragAndDrop = function(bVar)
{
vm.groupSortable.disabled = bVar;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.