我用jTable创建了一个Datagrid,下面是我的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>
控制器中的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;
}
我得到的结果是:
{"结果":"OK"、"记录":{" id ": 1、"名称":"测试","价格":"200","描述":"OK"}}
有人能告诉我我应该怎么做使用jTable与Symfony?一个实际的例子就很好了。非常感谢。
try with:
$product = array('id' => 1, 'Name' => "test",'Price' => "200",'Description' => "ok");