[英]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.