我希望为我的表单搜索部署一个数据表,以便使用 php 的 Solarium 客户端从 Apache solr 获取结果,对于每个结果,我将其转换为 JSON 格式,如下所示:在我的操作搜索中:
public function search() {
if($_POST){
// get a select query instance
$query = $client->createSelect()
->setQuery($forsearch )
->addParam('wt','json');
// this executes the query and returns the result
$resultset = $client->select($query);
$this->response->body(json_encode($result));
}
}
如何发送 json 文件来查看此函数中的大部分 url:
$('.datatable-ajax-source table').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "http://localhost/solr/users/search.json",
});
我不能使用 $this->autoRender = false;因为我需要从 search.ctp 输入 forsearch 来获取 $resulset
最佳答案
你好,伙计。 在 Controller 函数上,您必须将响应格式化为具有索引“data”的对象,并且该索引必须包含一个包含将由 Datatables 显示的列表的列表,它必须如下所示:
{
data: [
[field, field, field, field],
[field, field, field, field]........
]
}
不要忘记 implode() 某些字段,在您的情况下,您必须 implode() 字段“competence_txt”以使其成为字符串。
检查Datatables oficial website了解更多信息。
关于javascript - 如何在cakephp2.6中将json文件发送到dataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38795911/