【问题标题】:Symfony3 Tetranz/select2 - remote_routeSymfony3 Tetranz/select2 - remote_route
【发布时间】:2018-06-29 14:12:20
【问题描述】:

我正在尝试为我的项目使用 select2entity-bundle 来实现自动完成。

使用builder时,规范如下:

$builder
   ->add('country', Select2EntityType::class, [
            'multiple' => true,
            'remote_route' => 'tetranz_test_default_countryquery',
            'class' => '\Tetranz\TestBundle\Entity\Country',
            'primary_key' => 'id',
            'text_property' => 'name',
            'minimum_input_length' => 2,
            'page_limit' => 10,
            'allow_clear' => true,
            'delay' => 250,
            'cache' => true,
            'cache_timeout' => 60000, // if 'cache' is true
            'language' => 'en',
            'placeholder' => 'Select a country',
            // 'object_manager' => $objectManager, // inject a custom object / entity manager 
        ])

应该在“remote_route”参数中指定什么? 为什么我的字段应该链接到路线?应该如何以及在哪里配置此路由?它应该与查询相关联吗?

感谢您的帮助!

【问题讨论】:

    标签: php symfony bundle jquery-select2


    【解决方案1】:

    选择需要在用户键入时更新要显示的值。它通过向您需要编写的控制器发送请求来完成此操作,该控制器收集相关值并将它们作为 json 返回。

    创建一个控制器,返回要在选择中显示的项目列表,并使用您为该控制器定义的路由名称作为“remote_route”参数。

    返回数据的格式记录在 github https://github.com/tetranz/select2entity-bundle 上的 bundle 页面的中间

    【讨论】:

    • 您好菲尔,谢谢您的回答。如果您的答案尚未完全发送,我认为可能有问题。
    • 是的,很抱歉我提早提交,然后编辑没有采取。已更新。
    猜你喜欢
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2016-10-05
    • 1970-01-01
    • 2016-03-10
    • 2016-09-30
    • 2016-09-28
    相关资源
    最近更新 更多