1
我创建一个DataGrid与JTable中,这是我的JavaScript代码:列在JTable中不显示
<script type="text/javascript">
$(document).ready(function() {
$('#PersonTableContainer').jtable({
title: 'Table of people',
actions: {
listAction: '{{ path("person_list") }}',
createAction: '',
updateAction: '',
deleteAction: ''
},
fields: {
PersonId: {
key: true,
list: false
},
Name: {
title: 'Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
PaysId: {
title: 'Country',
width: '30%'
}
}
});
});
</script>
的代码工作正常,它会显示所有信息。
____________________________
Name | Age | Country
----------------------------
Mohssine | 22 | France
Saad | 10 | USA
____________________________
后,我加入这个代码:
options: '{{ path("get_countries") }}',
来为用户显示一个组合框,当他想改变或创建一个新的记录,下面的代码:
<script type="text/javascript">
$(document).ready(function() {
$('#PersonTableContainer').jtable({
title: 'Table of people',
actions: {
listAction: '{{ path("person_list") }}',
createAction: '',
updateAction: '',
deleteAction: ''
},
fields: {
PersonId: {
key: true,
list: false
},
Name: {
title: 'Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
PaysId: {
title: 'Country',
options: '{{ path("get_countries") }}',
width: '30%'
}
}
});
});
</script>
PHP代码:返回国家列表的函数
public function getCountriesAction()
{
$stmt = $this->getDoctrine()->getEntityManager()
->getConnection()
->prepare('select country as DisplayText,id as value from countries');
$stmt->execute();
$countries = $stmt->fetchAll();
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Options'] = $countries;
$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
$content = $serializer->encode($jTableResult, 'json');
return new Response($content);
}
当我显示我的数据网格时,所有的信息都在那里,除了我在代码中添加的列以外,它没有任何信息显示。
____________________________
Name | Age | Country
----------------------------
Mohssine | 22 |
Saad | 10 |
____________________________
请解决方案,谢谢。