首页 > 解决方案 > Opencart 3.0.3.2 - 在 Ajax + Twig 上抓取多维数组

问题描述

美好的一天,我在尝试获取 admin/view/template/catalog/product_form.twig ajax 函数上的数组以将其显示为自定义时遇到了一些麻烦<select>,该数组由autocomplete()admin/controller/catalog/option.php 上的函数给出,新的数组值存储在'parent_option_value' => $parent_option_value_data. 我一直在乱改诸如$('#option-values' + option_row)to$('#parent-option-values' + option_row)和其他元素之类的东西,但没有成功。

新的array()确实获得了数据,但我无法在第一个上显示它的值<select>。我需要添加和更改以使该数组显示为第二个选项值<select>吗?

管理员/视图/模板/目录/product_form.twig

      <!-- The Array I Need -->
      if (parent_option_id > 0) {
          html += '  <td class="text-left"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]" class="form-control">';
          html += $('#option-values' + option_row).html();
          html += '  </select><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][product_option_value_id]" value="" /></td>';
      }
      <!--/ The Array I Need /-->

      html += '  <td class="text-left"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]" class="form-control">';
      html += $('#option-values' + option_row).html();
      html += '  </select><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][product_option_value_id]" value="" /></td>';

管理员/控制器/目录/option.php

public function autocomplete() {
...
                if ($option['parent_id'] > 0) {
                    $json[] = array(
                        'parent_option_id'     => $option['parent_id'],
                        'option_id'            => $option['option_id'],
                        'name'                 => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
                        'category'             => $type,
                        'type'                 => $option['type'],
                        'parent_option_value'  => $parent_option_value_data,
                        'option_value'         => $option_value_data
                    );
                } else {
                    $json[] = array(
                        'parent_option_id'     => $option['parent_id'],
                        'option_id'            => $option['option_id'],
                        'name'                 => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
                        'category'             => $type,
                        'type'                 => $option['type'],
                        'option_value'         => $option_value_data
                    );
                }
            }
...

标签: phparraysajaxtwig

解决方案


推荐阅读