gpt4 book ai didi

javascript - Jtable 中的列不显示

转载 作者:行者123 更新时间:2023-11-28 01:43:37 25 4
gpt4 key购买 nike

我使用 JTable 创建了一个 Datagrid,这是我的 JavaScript 代码:

<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 |
____________________________

请提供解决方案,谢谢。

最佳答案

您必须更改您的函数getCountriesAction:

public function getregionsAction()
{
$stmt = $this->getDoctrine()->getEntityManager()
->getConnection()
->prepare('select country,id from countries');
$stmt->execute();
$countries= $stmt->fetchAll();



foreach ($countries= as $key => $value) {

$eil = array();
$eil["DisplayText"] = $countries[$key]['country'];
$eil["Value"] = $countries[$key]['id'];
$rows[] = $eil;
}

$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Options'] = $rows;

$serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
$content = $serializer->encode($jTableResult, 'json');
return new Response($content);
}

请检查:https://gist.github.com/cristic84/5883136

希望这个解决方案能够帮助您。

关于javascript - Jtable 中的列不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20583953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com