listen = $listen; return $this; } public function render() { $this->addVariables(['listen' => $this->listen]); return parent::render(); } /** * 格式化保存值 * * @param [type] $data * @return void */ protected function prepareInputValue($value) { $value = json_decode($value, true); $toValue = null; if($value){ foreach($value as $item){ $toValue[$item['name']] = $item['value']; } } return $toValue; } /** * 格式化渲染值 * * @param [type] $value * @return void */ protected function formatFieldData($data) { $value = parent::formatFieldData($data); $crop = Arr::get($this->variables, 'crop', null); $toValue = []; if($crop && $crop->extends){ $extends = json_decode($crop->extends, true); foreach ($extends as $ext){ $toValue[] = array_merge($ext, ['value'=>$value[$ext['name']] ?? null]); } } return json_encode($toValue); } public function crop($crop) { return $this->addVariables(['crop' => $crop]); } }