我試圖將'AbsoluteLink'屬性添加到DataList中的每個DataObject,然後使用JSONDataFormatter::convertDataObjectSet()
將列表轉換爲JSON。SilverStripe convertDataObjectSet正在剝離其他屬性
我有以下功能:
public function json() {
$data = ResourceCentreArticlePage::get()->filter('ShowInMenus', '1')->filter('ShowInSearch', '1')->sort('Created', 'DESC');
$pageArray = new ArrayList();
foreach ($data as $page) {
$page->AbsoluteLink = $page->AbsoluteLink();
$pageArray->push($page);
}
// If I dump out the content of $pageArray here the object has the AbsoluteLink property
$jsonFormatter = new JSONDataFormatter();
$jsonData = $jsonFormatter->convertDataObjectSet($pageArray);
// If I dump out the content of $jsonData here there is no AbsoluteLink property
$this->response->addHeader("Content-type", "application/json");
return $jsonData;
}
問題:
的AbsoluteLink屬性通過convertDataObjectSet
方法運行$pageArray
後除去。
我錯過了什麼?
凡你有意見'//如果我傾倒了$ pageArray的內容在這裏沒有AbsoluteLink property'你的意思是,如果你傾倒了$ jsonData的評論,或者是從$ pageArray實際丟失數據你說? –
啊好拿起來,那的確是爲了$ jsonData,現在就會更新。 – nickspiel