通过HABTM复选框/列表搜索

时间:2012-08-05 08:45:38

标签: list cakephp search checkbox has-and-belongs-to-many

我有这个联系表格,它也与其他几个有HABTM关系的表有关。它们以列表或复选框的形式显示在表单中。我想要的是能够在表单中搜索它们,以选择适用于我在表单中添加的联系人的那些。我不知道该怎么做 - 想想也许是Javascript?

当您在朋友列表中搜索时,我所谈论的一个例子就像Facebook一样。

以下是联系模式的HABTM关系:

    public $hasAndBelongsToMany = array(
    'Company' => array(
        'className' => 'Company',
        'joinTable' => 'companies_contacts',
        'foreignKey' => 'contact_id',
        'associationForeignKey' => 'company_id',
        'unique' => 'keepExisting',
        'dependent' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Event' => array(
        'className' => 'Event',
        'joinTable' => 'contacts_events',
        'foreignKey' => 'contact_id',
        'associationForeignKey' => 'event_id',
        'unique' => 'keepExisting',
        'dependent' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Screenoccupation' => array(
        'className' => 'Screenoccupation',
        'joinTable' => 'contacts_screenoccupations',
        'foreignKey' => 'contact_id',
        'associationForeignKey' => 'screenoccupation_id',
        'unique' => 'keepExisting',
        'dependent' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Tapearchive' => array(
        'className' => 'Tapearchive',
        'joinTable' => 'contacts_tapearchives',
        'foreignKey' => 'contact_id',
        'associationForeignKey' => 'tapearchive_id',
        'unique' => 'keepExisting',
        'dependent' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ),
    'Relation' => array(
        'className' => 'Contact',
        'joinTable' => 'contacts_contacts',
        'foreignKey' => 'contact_id',
        'associationForeignKey' => 'related_id',
        'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    )
);

不确定我需要向您展示其他代码,所以请让我知道需要哪些代码,我会将它们添加到这个问题中。

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用jquery插件为您完成这项工作。

似乎this one符合您的条件。 Chosen也很好。

无论如何,进行谷歌搜索以查看所有可用的jquery插件,看看是否符合您的需求。