我正在尝试使用 Zend Framework 将 jQuery DataTables 实现为“新”表单,我在控制器中设置了以下操作:
public function ajaxFindQuotesAction()
{
$this -> setNoRender();
$quoteTable = new Model_QuotesTable();
$select = $quoteTable->select();
$select -> from($quoteTable, array('qte_id', 'qte_description'));
$rows = $quoteTable->fetchAll($select);
$json = Zend_Json::encode($rows->toArray());
echo($json);
}
我还在视图中设置了以下代码:
<?php $this->inlineScript()->captureStart(); ?>
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": '/jobs/ajax-find-quotes'
} );
} );
<?php $this->inlineScript()->captureEnd(); ?>
<table class="display dataTable" id="example" >
<thead>
<tr>
<th>ID</th>
<th>Title</th>
</tr>
</thead>
</table>
问题是,当前的 JSON 输出如下:
[
{
"column_1":"value 1",
"column_2":"value 2"
},
{
"qte_id":"3",
"qte_description":"go to the zoo"
}
]
虽然 DataTables 需要这种格式(从示例文件复制):
{
"aaData": [
[
"value 1",
"value 2"
],
[
"Trident",
"Internet Explorer 5.0"
]
]
}
有任何想法吗?非常感谢您提前