1
我如何可以操纵/更改返回JSON:TYPO3 Extbase - 操纵/更改返回JSON
[{
"name": "Audi",
"owner": "Peter",
"price": 0,
"color": "Blue",
"pid": 0,
"uid": 1
}, {
"name": "BMW",
"owner": "Wolfgang",
"price": 0,
"color": "Black",
"pid": 0,
"uid": 2
}]
到如:
{
"data": [{
"DT_RowId": "row_1",
"name": "Audi",
"owner": "Peter"
}, {
"DT_RowId": "row_2",
"name": "BMW",
"owner": "Wolfgang"
}],
"options": [],
"files": [],
"draw": 1,
"recordsTotal": "2",
"recordsFiltered": "16"
}
我在我的控制器试过,但它甚至没有过滤名称&所有者:
/**
* @var string
*/
protected $defaultViewObjectName = 'TYPO3\CMS\Extbase\Mvc\View\JsonView';
public function jsonRequestAction() {
$this->view->setVariablesToRender(array('records'));
$this->view->setConfiguration(array(
'records' => array(
'only' => array('name', 'owner')
)
)
);
$this->view->assign('records', $this->leiRepository->jsonRequest());
}
我仍然获得标准json中的所有字段。
这是从库中的函数:
public function jsonRequest() {
$query = $this->createQuery();
$result = $query->setLimit(1000)->execute();
//$result = $query->execute();
return $result;
}
你能从'$ this-> leiRepository-> jsonRequest()'发布代码吗? –
从jsonRequest()的存储库中的函数?我上面提供了... –
你如何获得JSON?没有看到任何'json_encode()'或类似的。 –