如何禁用列表的第一项以使其无法排序并放下目标 [英] how to disable first item of a list from being sortable and drop target
问题描述
我有一个项目列表,我想使列表中的第一个项目不可排序和不可移动.列表中的第一项应始终保持列表中的第一项.但是,我似乎无法正常工作.这是我的排序代码:
I have a list of items and I want to make the first item in the list unsortable and unmovable. The first item in the list should always stay as the first item in the list. However, I can't seem to get it to work.here's my sorting code:
jQuery ->
$('#lineup').sortable(
axis: 'y'
items: ".ui-state-enabled"
cancel: ".ui-state-disabled"
update: ->
$.post($(this).data('update-url'), $(this).sortable('serialize'))
);
并且我正在使用content_tag_for进行加载:
and i'm using content_tag_for to load it up:
%ul.nav.nav-tabs.nav-stacked#lineup{"data-update-url" => sort_lineups_url}
- @pieces.each_with_index do |piece, index|
- if index == 0
= content_tag_for(:li, piece, :class => 'ui-state-disabled') do
= link_to "#{(index + 1).to_s + ' - ' + piece.name}", '#'
- else
= content_tag_for(:li, piece, :class => 'ui-state-enabled') do
= link_to "#{(index + 1).to_s + ' - ' + piece.name}", '#'
我在做什么错?我似乎没有采取任何措施来阻止对第一项进行排序和/或移动
what am i doing wrong? nothing i do seems to prevent the first item from being sorted and/or moved
推荐答案
嗯,很难确定.我以前没有使用过可排序/可拖动的组合,而且UI文档未明确说明可排序/可拖动的组合.
Mmm, hard to say for certain. I've not used sortable/draggable combination before, moreover the UI documentation doesn't expressly address the sortable/draggable combination.
但是,从我在文档中阅读的内容来看,类似的东西应该可以工作:
However, from what I have read in the documentation, something like this should work :
$(function() {
$("#lineup li").disableSelection().addClass('ui-state-default').eq(0).addClass('ui-state-disabled');//alternatively, write classes as HTML attributes
$("#lineup").sortable({
items: "li:not(.ui-state-disabled)" //should disable draggable and sortable
});
});
这篇关于如何禁用列表的第一项以使其无法排序并放下目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!