问题描述
有时列表会连接,您可以在它们之间进行转移。 其他时候它不连接。 您可以随时在每个列表中进行排序,但有时不能在它们之间进行排序。 我不知道。
$('#questions .survey-page ul').sortable({
items: 'li:not(.placeholder)',
sort: function() {
$(this).removeClass('ui-state-edit'); // While sorting we do not want edit buttons to show.
},
update: function() {
refreshAllDetails(); // Update survey with the new details.
},
connectWith: '#questions .survey-page ul'
});
#question
是将多个.survey-page
子项放入的标签。
每个.survey-page
都有一个带有多个li
条目的ul
。
我正在尝试在.survey-page
之间链接此ul
。
编辑:根据要求:
/** * Saves the order of questions, then saves the details of all questions to server. */ function refreshAllDetails() { saveOrder(); saveAllToDatabase(); } /** * Saves the details of all questions to server. */ function saveAllToDatabase() { // Go through each page. $("#questions").find(".survey-page").each(function() { var surveypage = this; // Save metadata for current page. // Go through each question on page. $(this).find(".questiontypestuffp").each(function() { // Get the answers for a particular question, including meta-data for question. var result = callWidget($(this), "getEditedAnswers"); // Get the order of the question listed on page. result.questionorder = $(this).attr('ordervalue'); result.pageno = $(surveypage).attr("ordervalue"); // Save the question's order to its associated widget. callWidget($(this), "setData", result); // Update the question in database. $.ajax({dataType: "json", url: "index.php?option=com_survey&loadorsave=update&view=surveydata&layout=edit&id=" + $("#itemid").val() + "&tmpl=component&format=json&questionvalues=" + encodeURI(JSON.stringify(result)), success: function(callback) { }}); // Turn off edit mode. setEditModeOff(); }); }); } /** * Refreshes order values with regard to their position on page. This rewrites the order values as they appear. */ function saveOrder() { var pageorder = 0; // GO through each page. $("#questions").find(".survey-page").each(function() { var questionorder = 0; // Rewrite page order. var currentPage = ++pageorder; $(this).attr('ordervalue', currentPage); // Rewrite each question's order on page. $(this).find(".questiontypestuffp").each(function() { $(this).attr('ordervalue', ++questionorder); }); }); }
1楼
我已经在这里解决了我自己的问题。 实际上,我要删除的类需要识别拖放操作,因此需要“ ui-state-edit”。 通过与DOM元素之间动态更新此类,这影响了列表项是否能够在列表之间传输。 简要来说-拖放拒绝列表项,因为它没有有效的类名。