gpt4 book ai didi

drop-down-menu - 组合选择列表中的列 Symfony 形式

转载 作者:行者123 更新时间:2023-12-04 06:29:48 24 4
gpt4 key购买 nike

在我的 Symfony 表单中,我有一个 choiceType 字段列出类别。我的类别表如下所示:

id code categorie
1 100 First categorie
2 200 Second categorie
3 210 Second subcategorie

在我的表单中,我有一个选择字段,并且通过 'choice_label' 我可以决定用于选择列表的“代码”或“类别”列。我想同时使用两者,以便用户显示一个选择列表:
  • 100第一类
  • 200 第二类
  • ..等

  • 是否可以加入choice_label的2列;连接字符串中的 2 列只是为了显示选择选项?
    我试图在这里和其他地方找到它。官方 docs不要提及此选项。

    最佳答案

    即使在 choice_label 的 ChoiceType 中,您也可以使用 callable 来设置它 link

    'choice_label' => function($category, $key, $index) {
    /** @var Category $category */
    return $category->getId() . ' ' . $category->getName();
    },

    但是你为什么要为你的类别使用ChoiceType,你将如何设置选择?为什么不用 EntityType?
    ->add('category', EntityType::class, array(
    'choice_label' => function ($category) {
    return $category->getId() . ' ' . $category->getName();
    },
    'class' => 'AppBundle:Category',
    'query_builder' => function (EntityRepository $er) {
    return $er->createQueryBuilder('c')
    ->orderBy('c.id', 'ASC');
    },
    ))

    关于drop-down-menu - 组合选择列表中的列 Symfony 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617786/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com