【问题标题】:jquery ui sortable with angularjs, how to prevent horizontal drag and drop? axis:y not workingjquery ui可使用angularjs排序,如何防止水平拖放?轴:y不工作
【发布时间】:2017-02-04 15:49:37
【问题描述】:

我正在使用可通过 angularjs 排序的 jquery ui 我正在这样做:

$scope.sortableOptions = {
            start: function(e, ui) {
                $(this).attr('data-previndex', ui.item.index());
            },
            update: function(e, ui) {
                $(this).removeAttr('data-previndex');
            },
            receive: function(e, ui) {
            },
            stop: function(event, ui) {
                var val = ui.item.attr("val");
                $("#list"+val+" li").each(function(i, el){
                    $scope.updateTop(val,el.id,i);
                });
                $("#list"+val+"sub li").each(function(i, el){
                    $scope.updateBottom(val,el.id);
                });
            },
            connectWith: ".group",
            axis: 'y',
            placeholder: 'placeholder',
            helper: "clone",
            dropOnEmpty: true,
        };

如您所见,我已经给出了轴:y,因此它应该只允许垂直拖放,但水平拖放也可以。我不需要水平拖放。有没有其他选择可以解决这个问题? Html 看起来像:

    <div class="row">
    <div class="col-md-12 sortable">
        <table cellpadding="0" cellspacing="0">
            <td ng-repeat="amount_info in amount_data" valign="top" width="300">
                    <!--sort list-->
                    <ul ui-sortable="sortableOptions" id="list{{amount_info.amount}}" class="group so_list{{amount_info.amount}}" ng-model="amount_info.sortList" >
                        <li ng-mouseup="mouseUp(sortItem.ProductId,amount_info.amount)" amount="{{amount_info.amount}}" ng-repeat="sortItem in amount_info.sortList track by $index" ProductId="{{sortItem.ProductId}}" id="prod_{{sortItem.ProductId}}">
                        <div id="tc_prod">
                                {{sortItem.Product}} [{{sortItem.ProductId}}] 
                            </div>
                        </li>
                    </ul>
                    <div class="listdivide"></div>
                    <ul ui-sortable="sortableOptions" id="list{{amount_info.amount}}sub" class="group so_list{{amount_info.amount}}"  ng-model="amount_info.nonSortList" >
                        <li  ng-repeat="nonsortItem in amount_info.nonSortList track by $index" productId="{{nonsortItem.ProductId}}" id="prod_{{nonsortItem.ProductId}}" amount="{{amount_info.amount}}">
                            {{nonsortItem.Product}} [{{nonsortItem.ProductId}}]
                        </li>
                    </ul>
                </div>
            </td>
        </table>
    </div>
</div>

每个表 td 在 ul 中都有一个列表。不应将一个 td 中的项目拖到另一个 td。但并非不可能。 Axis:y 给出但没有效果。有没有办法解决这个问题?

【问题讨论】:

    标签: javascript jquery angularjs jquery-ui


    【解决方案1】:

    通过添加以下代码解决了这个问题。

    beforeStop:函数(事件,用户界面){ if($(ui.helper).parent().attr('class') != $(ui.placeholder).parent().attr('class')){ 返回假; } },

    每个 ul 应该有单独的类并检查一个条件以查看发送者和接收者的类是否相同,否则允许返回 false。

    【讨论】:

      【解决方案2】:

      y 轴应该可以工作,这里是工作codepen

      在这个我用过

      axis:'y'
      

      还有和你给出的相同的配置选项

      【讨论】:

      • 我有多个表格列。在每一个中,我都有 ul li 列表。实际上我只需要在每个 td 中拖放。但它可以从一个 td 拖动到另一个。轴 y 在我的情况下不起作用。
      • 我认为您将不得不更改表格的结构,因为 ui 可对元素进行排序,并且在表格中元素按行而不是按列呈现。
      • 我的 td 包含列表。我有很多这样的 td 元素。我已经用 html 更新了我的问题。你可以看看 html 并告诉我它是否是 jquery ui sortable 支持的东西吗?
      • 哦,那么您可以在可排序选项中使用“items”属性,基本上创建为每个列表提供一个不同的可排序选项对象,该对象具有所有常见属性,但具有唯一选择器的 items 属性对于每个可以解决 yoru 问题的列表,我猜
      • 谢谢,会调查的。
      猜你喜欢
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多