* zin: output page data to client

This commit is contained in:
Hao Sun
2023-02-15 11:21:29 +08:00
parent 495a33c9c4
commit 3c29fb17a9
3 changed files with 21 additions and 8 deletions
+3 -3
View File
@@ -105,7 +105,7 @@ class props extends \zin\utils\dataset
public function addChildren($items)
{
$this->addBlock('default', $items);
$this->addBlock('children', $items);
}
public function getBlock($name)
@@ -116,7 +116,7 @@ class props extends \zin\utils\dataset
public function getChildren()
{
return $this->getBlock('default');
return $this->getBlock('children');
}
/**
@@ -197,7 +197,7 @@ class props extends \zin\utils\dataset
{
$data = $this->data;
$data['style'] = $this->style->data;
$data['class'] = $this->class->list;
$data['class'] = $this->class->toStr();
return $data;
}
+17 -4
View File
@@ -243,13 +243,26 @@ class wg
}
}
protected function created()
{
}
protected function created() {}
protected function toJsonData()
{
$data = $this->props->toJsonData();
foreach($data as $key => $value)
{
if($key[0] !== '#') continue;
foreach($value as $index => $child)
{
if($child instanceof wg || (is_object($child) && method_exists($child, 'toJsonData')))
{
$value[$index] = $child->toJsonData();
}
}
$data[$key] = $value;
}
$data['$type'] = get_called_class();
if(strpos($data['$type'], 'zin\\') === 0) $data['$type'] = substr($data['$type'], 4);
return $data;
}
protected static function getDefaultProps()
+1 -1
View File
@@ -42,7 +42,7 @@ class pagebase extends wg
(
set($this->prop('bodyProps')),
parent::build(),
$config->debug ? h::js('window.zin = ' . json_encode($this->props->toJsonData()) . ';console.log("page", window.zin)') : null // TODO: support to export page data to client
$config->debug ? h::js('window.zin = ' . json_encode($this->toJsonData()) . ';console.log("page", window.zin)') : null
)
);
}