我在循环遍历表格中的每个条目时遇到问题。以下是我迄今为止提出的建议:
<script>
$( document ).ready(function() {
$( "td.sorting_1" ).each(function() {
var entry = $( this ).children( "a" );
var sitename = $( entry ).attr('href');
var sitenametest = sitename.lastIndexOf('/');
var ug = sitename.substring(sitenametest + 1)
var countTasks = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .task" ).length;
var countTasksOverdue = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskoverdue" ).length;
var countTasksDueToday = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskduetoday" ).length;
var countTasksDueTomorrow = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskduetomorrow" ).length;
$( entry ).closest("tr").append( "<td>" + countTasksOverdue + "</td><td>" + countTasksDueToday + "</td><td>" + countTasksDueTomorrow + "</td><td>" + countTasks + "</td>" );
$( "table#caseSummary thead tr" ).append( "<th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='OverdueTasks' style='width: 70px;'>Overdue Tasks</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TasksDueToday' style='width: 70px;'>Tasks Due Today</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TasksDueTomorrow' style='width: 70px;'>Tasks Due Tomorrow</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TotalTasks' style='width: 70px;'>Total Tasks</th>" );
});
});
</script>
答案 0 :(得分:0)
<script>
function go()
{
var entries = $( "td.sorting_1 a" );
var entryIndex = 0;
$( "table#caseSummary thead tr" ).append( "<th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='OverdueTasks' style='width: 70px;'>Overdue Tasks</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TasksDueToday' style='width: 70px;'>Tasks Due Today</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TasksDueTomorrow' style='width: 70px;'>Tasks Due Tomorrow</th><th class='sorting' tabindex='0' aria-controls='caseSummary' rowspan='1' colspan='1' aria-label='TotalTasks' style='width: 70px;'>Total Tasks</th>" );
for ( entryIndex = 0; entryIndex < entries.length; entryIndex++ )
{
addRow( entries[entryIndex] );
}
}
function addRow( entry )
{
var sitename = $( entry ).attr('href');
var sitenametest = sitename.lastIndexOf('/');
var ug = sitename.substring(sitenametest + 1)
var countTasks = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .task" ).length;
var countTasksOverdue = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskoverdue" ).length;
var countTasksDueToday = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskduetoday" ).length;
var countTasksDueTomorrow = $( ".groupheader:contains('" + ug + "')" ).next( "ul.dfwp-list" ).find( "li.dfwp-item .taskduetomorrow" ).length;
$( entry ).closest("tr").append( "<td>" + countTasksOverdue + "</td><td>" + countTasksDueToday + "</td><td>" + countTasksDueTomorrow + "</td><td>" + countTasks + "</td>" );
}
$( document ).ready( go );
</script>