Symfony2 中带有 formType 和 Doctrine2 的 jQuery 自动完成字段
我有 2 个实体通过“OneToMany”关系链接。 其中一个实体是对象City
。该对象对应的表包括近37000个条目。 当我继续创建表单来填充 Symfony 中的 Proprietairy 实体时,我使用如下所示的 FormType。它包括一个对应于 City 对象的字段
namespace Immo\BienBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ProprietaireType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder
->add('nom')
->add('prenom')
->add('email')
->add('telephone')
->add('adresse')
->add('city', 'entity', array(
'class'=>'Immo\BienBundle\Entity\City',
'property'=>'city'));
}
public function getName() {
return 'immo_bienbundle_proprietairetype';
}
}
。该表单呈现一个组合框。涵盖 36000 个城市,加载时间非常长。我尝试过选项 fetch="extra_lazy",但它仍然不够高效。 我的想法是创建一个带有 ajax 输入字段的表单,并在用户提供 2 个字母后显示城市列表。我将感谢社区提供的任何帮助,以便在验证时与我的对象创建所需的关系。
I got 2 entities linked by a 'OneToMany' relationship.
One of the entities is the object City
. The table corresponding to this object includes almost 37000 entries.
When I proceed to the creation of a form to populate the Proprietairy entity in Symfony, I use a FormType which looks like below. It includes a field corresponding to the City Object
namespace Immo\BienBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ProprietaireType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder
->add('nom')
->add('prenom')
->add('email')
->add('telephone')
->add('adresse')
->add('city', 'entity', array(
'class'=>'Immo\BienBundle\Entity\City',
'property'=>'city'));
}
public function getName() {
return 'immo_bienbundle_proprietairetype';
}
}
The form renders a combobox. populated by the 36000 cities and takes incredibly long to load. I have tried the option fetch="extra_lazy", but it is still not efficient enough.
My idea was to create a form with an input field working with ajax and displaying the list of the cities after the user provides 2 letters. I would appreciate any help from the community to create the needed relationship with my Object when validating.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 https://github.com/symfony/symfony/pull/1951
我希望很快就会在 v2.1 中......
Use https://github.com/symfony/symfony/pull/1951
Soon in the v2.1 I hope...
您可以使用我的捆绑包 https://github.com/shtumi/ShtumiUsefulBundle 获取 ajax 自动完成表单类型
You can use my bundle https://github.com/shtumi/ShtumiUsefulBundle to get ajax autocomplete form type