在joomla 3中如何包含自动完成搜索

时间:2013-09-07 01:50:23

标签: php ajax jquery joomla

我正在创建自定义组件,因为我正在使用自定义 fieldtype(mycomponent / models / fields / productcategory.php)创建产品类别列表框。它还显示右侧的产品包装方式。

我需要创建选择列表框并自动完成搜索,如模块管理器中的位置字段..

任何人都知道解决方案..

1 个答案:

答案 0 :(得分:2)

我使用select.js解决了我的问题。

jQuery编码是:

jQuery(document).ready(function($) {
  jQuery(".productcat").change(function(){
    fk_productcat = $("#" + this.id).val();
    //alert(fk_productcat);
    jQuery.ajax({
      url:'index.php?option=com_gwerp&task=stocks.getListArticles',
      type: "POST",
      data: {
        'fk_productcat': fk_productcat
      }
    }).done(function(msg) {
      console.log(msg);
      jQuery(".product").html(msg);
      jQuery( ".product" ).val(msg).trigger( "liszt:updated" );
      jQuery("#jform_fk_product_code").select2();
    })
  })
});

jQuery(document).ready(function() {
  jQuery("#jform_fk_productcat").select2();
});

jQuery(document).ready(function() {
  jQuery("#jform_fk_product_code").select2();
});

我通过引用this url来调用Ajax文件。