我用 jTable 创建了一个 Datagrid,这是我在 twig 中的 JavaScript 代码:
<script type="text/javascript">
$(document).ready(function () {
jQuery('#grid').jtable({
title: 'Table of product',
paging: true,
pageSize: 2,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: '{{path("_db_show")}}',
createAction: '{{path("_serverproc")}}?action=create',
updateAction: '{{path("_serverproc")}}?action=update',
deleteAction: '{{path("_serverproc")}}?action=delete'
},
fields: {
id: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '40%'
},
Price: {
title: 'Price',
width: '20%'
},
Description: {
title: 'Description',
width: '30%',
}
}
});
//Load person list from server
$('#grid').jtable('load');
});
</script>
以下是 Controller 中的php代码:
/**
* @Route("/show", name="_db_show")
* @Template()
*/
public function showAction()
{
$product = array({'id' => 1, 'Name' => "test",'Price' => "200",'Description' => "ok"});
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $product;
$JsonResponse = new JsonResponse($jTableResult);
return $JsonResponse;
}
我得到的结果是:
{"结果":"确定","记录":{"id":1,"名称":"测试","价格":"200","描述":"确定"}}
有人可以告诉我如何在 Symfony 中使用 jTable 吗?一个有效的例子会很棒。非常感谢。
最佳答案
尝试:
$product = array('id' => 1, 'Name' => "test",'Price' => "200",'Description' => "ok");
数组定义中没有 {};
关于javascript - jTable 如何与 Symfony 2 配合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25201555/