首页 > 解决方案 > Opencart 1.5.6 删除模块上的类别自动完成

问题描述

试图删除模块上的自动完成功能,我想让它列出所有类别,并带有一个复选框以供选择而不是自动完成,这是代码的样子,有什么建议吗?我知道它需要在第 3 行进行一些更改。

.'<tr class="category" '.(($this->data['xshippingpro']['category'][$no_of_tab]!=1)?'style="display:table-row"':'').'>'
                  .'<td>'.$this->data['entry_category'].'</td>'
                  .'<td><input type="text" name="category" value="" /></td>'
                .'</tr>'
                .'<tr class="category" '.(($this->data['xshippingpro']['category'][$no_of_tab]!=1)?'style="display:table-row"':'').'>'
                  .'<td>&nbsp;</td>'
                  .'<td><div class="scrollbox product-category">';
                  foreach ($this->data['xshippingpro']['product_category'][$no_of_tab] as $category_id) {
                           $category_name=$this->getPath($category_id);
                           $return.='<div class="product-category'.$category_id. '">'.$category_name.'<img src="view/image/delete.png" alt="" />'
                             .'<input type="hidden" class="category" name="xshippingpro[product_category]['.$no_of_tab.'][]" value="'.$category_id.'" /></div>';
                        }
                  $return.='</div></td>'
                .'</tr>'

这是处理获取数据调用的代码的另一部分......

public function get_categories() {
        $json = array();

        if (isset($this->request->get['filter_name'])) {



            $results = $this->getCategories($this->request->get['filter_name']);

            foreach ($results as $result) {
                $json[] = array(
                    'category_id' => $result['category_id'], 
                    'name'        => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
                );
            }       
        }

        $sort_order = array();

这是代码的javascript部分

$('input[name=\'category\']').autocomplete({
            delay: 500,
            source: function(request, response) {
                $.ajax({
                    url: 'index.php?route=shipping/xshippingpro/get_categories&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
                    dataType: 'json',
                    success: function(json) {       
                        response($.map(json, function(item) {
                            return {
                                label: item.name,
                                value: item.category_id
                            }
                        }));
                    }
                });
            }, 
            select: function(event, ui) {
                var no_of_tab=$(this).closest('div.shipping').attr('id');
                no_of_tab=no_of_tab.replace('shipping-','');
                no_of_tab=parseInt(no_of_tab);
                $('#form #shipping-'+no_of_tab+' .product-category' + ui.item.value).remove();

                $('#form #shipping-'+no_of_tab+' .product-category').append('<div class="product-category' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input type="hidden" class="category" name="xshippingpro[product_category]['+no_of_tab+'][]" value="' + ui.item.value + '" /></div>');       
                return false;
            },
            focus: function(event, ui) {
              return false;
           }
        });

        $('.product-category div img').live('click', function() {
            var no_of_tab=$(this).closest('div.shipping').attr('id');
                no_of_tab=no_of_tab.replace('shipping-','');
                no_of_tab=parseInt(no_of_tab);
            $(this).parent().remove();  
        });

        $('select.category-selection').live('change', function() {
            var no_of_tab=$(this).closest('div.shipping').attr('id');
                no_of_tab=no_of_tab.replace('shipping-','');
                no_of_tab=parseInt(no_of_tab);
             if($(this).val()=='1'){
                $('#form #shipping-'+no_of_tab+' tr.category').css('display', 'none');
             }else{
               $('#form #shipping-'+no_of_tab+' tr.category').css('display', 'table-row');
             }
        });

标签: javascriptphpopencart

解决方案


推荐阅读