发布 yaml
repeater_data:
label: Repeater
prompt: 'Add new item'
maxItems: '5'
span: full
type: repeater
form:
fields:
blocks:
label: Dropdown
span: full
type: dropdown
options: blocksToAdd
post.php 模型
protected $jsonable = ['blocks'];
public function blocksToAdd()
{
$blocks = Block::pluck('title');
//$jenkebOptions= [''];
foreach ($blocks as $item) {
// json decoding
$decoded = json_decode($item, true);
$jenkebOptions[] = $decoded;
log::info($decoded);
}
return $jenkebOptions;
}
谢谢。...
答案 0 :(得分:0)
不确定为什么要json_decode
,或者我想念什么
在正常情况下,您需要返回values and title
对的数组
public function blocksToAdd()
{
return Block::pluck('title','id');
}
只要这样做,它将返回数组
[1 => 'title 1', 2 => 'title 2']
,现在在下拉标题[title]中分别可见其值[id]
如果您需要标题作为值基础,那么您可以这样做
public function blocksToAdd()
{
$blockTitles = Block::pluck('id','title');
$blockTitlesArray = [];
foreach($blockTitles as $title) {
$blockTitlesArray[$title] = $title;
}
return $blockTitlesArray;
}
如有疑问,请发表评论。