我有一个for循环,从我的数据库中获取json数据并填充表。我试图让表格的每一行都可以排序,我设法做了但是当我尝试使用ui.item.index()+ 1时;它给出了错误的索引
<input type='button' id='prioritySetSubmit' value='Set Priority'>
<div title='Priority Set' id='setPriority'> </div>
$(function()
{
$('#prioritySetSubmit').click(function()
{
$( "#setPriority" ).dialog();
$.get("geterrors.php", function(data)
{
var priorityCount = 1;
var errors = JSON.parse(data);
var setPriorityTable = "<table id='setPriorityTable'> <tr> <th> Business Name </th>
<th> Summery </th> <th> Date </th> <th> Priority </th> </tr>";
for(i=0; i<errors.length; i++)
{
setPriorityTable += "<tbody class='priorityClass'> <tr>";
setPriorityTable += "<td>" + errors[i]['business_name'] + "</td>";
setPriorityTable += "<td>" + errors[i]['error_summery'] + "</td>";
setPriorityTable += "<td>" + errors[i]['date'] + "</td>";
setPriorityTable += "<td>" + priorityCount + " </td> </tr> </tbody>";
++priorityCount;
}
$("#setPriority").html(setPriorityTable);
$( ".priorityClass" ).sortable({
placeholder: "ui-state-highlight",
connectWith: ".priorityClass",
start: function(event, ui) {
ui.item.startPos = ui.item.index() + 1;
},
stop: function(event, ui) {
ui.item.finishPos = ui.item.index() + 1
console.log("Start position: " + ui.item.startPos);
console.log("New position: " + ui.item.finishPos);
}
});
});
});
});