我用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;
}我得到的结果是:
{"Result":"OK","Records":{"id":1,"Name":"test","Price":"200","Description":"ok"}}
有人能告诉我在Symfony中使用jTable应该怎么做吗?一个工作的例子就很好了。非常感谢。
发布于 2015-04-24 20:43:43
尝试使用:
$product = array('id' => 1, 'Name' => "test",'Price' => "200",'Description' => "ok");数组定义中没有{};
https://stackoverflow.com/questions/25201555
复制相似问题