self::TYPE_CHECKED, 'data' => [], 'multiple' => true ]; /** * @var array */ protected static $propsRule = [ 'type' => 'string', 'multiple' => 'boolean', 'showCheckbox' => 'boolean', 'emptyText' => 'string', ]; /** * @param array $treeData * @return $this */ public function data(array $treeData) { if (!is_array($this->props['data'])) $this->props['data'] = []; foreach ($treeData as $child) { $this->props['data'][] = $child instanceof TreeData ? $child->build() : $child; } return $this; } /** * @param $var * @return $this */ public function jsData($var) { $this->props['data'] = 'js.' . $var; return $this; } /** * @param $value * @return $this */ public function value($value) { if (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = (string)$v; } } else { $value = (string)$value; } $this->value = $value; return $this; } public function getValidateHandler() { if ($this->props['multiple']) return Validate::arr(); else return Validate::str(); } /** * @return array */ public function build() { return [ 'type' => $this->name, 'field' => $this->field, 'title' => $this->title, 'value' => $this->value, 'props' => (object)$this->props, 'validate' => $this->validate, 'col' => $this->col ]; } }