【发布时间】:2015-03-10 16:40:02
【问题描述】:
我正在开发一个带有 java play 的网络应用程序!框架,在特定视图中,我使用 DataTable 来显示客户列表,我需要将名称列作为链接,点击它应该显示客户表。
我的问题是这个 sn-p:
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html(
'<a href="@routes.Dashboard.dettagliCliente("'+aData[3]+'")">'+aData[0] + '</a>');
return nRow;
}
当应用程序运行时,我单击给定的客户,视图到达控制器,但它没有将 aData[3] 的值传递给方法,而是按字面意思传递字符串“aData[3]”
这是具体路线:
GET /dashboard/dettagli_cliente/:idCliente controllers.Dashboard.dettagliCliente(idCliente:String)
这是控制器:
public static Result dettagliCliente(String id){
Logger.info("CUSTOMER ID "+id);
final Cliente cliente = Cliente.findById(id);
Form<Cliente> formCliente = Form.form(Cliente.class).bindFromRequest();
Form<Cliente> filledForm = formCliente.fill(cliente);
return ok(registra_utente_form.render(User.findByEmail(request().username()),filledForm,cliente));
}
更新: 这是视图上完整的 dataTable 调用:
$(document).ready(function() {
$('#clienti_table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "@routes.Dashboard.testList()",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html('<a href="@routes.Dashboard.dettagliCliente("'+aData[3]+'")">'+aData[0] + '</a>');
return nRow;
},
});
});
如果我在 href 属性内写了一个示例客户 ID 而不是 aData[3],它会起作用:单击其中一个客户列表元素,它会打开该给定客户(ID)的详细信息
这是一个例子:
$(document).ready(function() {
$('#clienti_table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "@routes.Dashboard.testList()",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html('<a href="@routes.Dashboard.dettagliCliente("c0ed22dc-6c92-4a70-ad30-ea73e8b0c314")">'+aData[0] + '</a>');
return nRow;
},
});
});
谢谢大家
【问题讨论】:
标签: java playframework