我正在尝试在刷新容器div后应用jQuery数据表结构。
我有一个div,其中有数据表。对于第一次访问,它工作正常,但是在单击按钮事件时,我正在刷新它的父div。之后,我期望表上有数据表结构,但无法正常工作。
<div id="students">
<table id="studTable" class="table fullwidth data">
<thead>
<tr>
<th> Name</th>
<th> DOB</th>
<th> Email</th>
</tr>
</thead>
<tbody>
@foreach (var stud in Model)
{
<tr>
<td>@stud.Name</td>
<td>@stud.DOB</td>
<td>@stud.Email</td>
</tr>
}
</tbody>
</table>
</div>
我正在MVC视图中从模型读取数据。首次加载时,它显示了jQuery数据表结构。在按钮上单击,我将执行以下jQuery代码:
<script type="text/javascript">
$(".submit").click(function (event) {
$("#students").load(location.href + " #students");
$("#studTable").dataTable({
"bSort": false,
"bPaginate": true,
"bInfo": true,
"bFilter": false,
"bLengthChange": false,
"pagingType": "simple_numbers",
});
})
</script>
此代码会重新加载学生 div,但数据表未应用。 当我在 setTimeout 函数中编写数据表的代码时,它会正确加载jQuery数据表。
setTimeout(function () {
}, 1000);
但是在这里我不想使用这个setTimeout(function(){},1000);
这种情况有解决方案吗?
答案 0 :(得分:1)
Code:
Retry Analyzer:
public class RetryAnalyzer implements IRetryAnalyzer{
int counter = 0;
int retryLimit = 1;
public boolean retry(ITestResult result){
if(counter<retryLimit){
counter++;
return true;
}
return false;
}
}
@BeforeMethod
public void aSetup(Method method) {
Report.loadConfig(new File(".\\Reports\\extent-config.xml"));
logger = Report.startTest(method.getName());
}
函数是异步的,因此有效地尝试在内容完成加载之前应用DataTables插件。不用在下一行代码中应用插件,而是在异步回调中应用它:
.load()