mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Use native json_encode to convert treeView objects to JSON.
This should improve the performance.
This commit is contained in:
parent
fbcfc1f2a8
commit
811dca691b
4 changed files with 60 additions and 11 deletions
|
@ -30,7 +30,7 @@ use App\Helpers\Trees\TreeViewNodeState;
|
|||
* This class represents a node for the bootstrap treeview node.
|
||||
* When you serialize an array of these objects to JSON, you can use the serialized data in data for the treeview.
|
||||
*/
|
||||
class TreeViewNode
|
||||
class TreeViewNode implements \JsonSerializable
|
||||
{
|
||||
protected $text;
|
||||
protected $href;
|
||||
|
@ -206,4 +206,32 @@ class TreeViewNode
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$ret = [
|
||||
'text' => $this->text
|
||||
];
|
||||
|
||||
if($this->href !== null) {
|
||||
$ret['href'] = $this->href;
|
||||
}
|
||||
|
||||
if($this->tags !== null) {
|
||||
$ret['tags'] = $this->tags;
|
||||
}
|
||||
|
||||
if($this->nodes !== null) {
|
||||
$ret['nodes'] = $this->nodes;
|
||||
}
|
||||
|
||||
if($this->state !== null) {
|
||||
$ret['state'] = $this->state;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue